| Author |
Topic |
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-01-09 : 06:10:43
|
| hi,can i disable primary key constraint on a column of a table in sql server 2005.??thanks in advance |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-01-09 : 06:12:04
|
| yes if no FK are bound to it_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-01-09 : 06:16:56
|
quote: Originally posted by spirit1 yes if no FK are bound to it_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
how???? |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-01-09 : 06:30:13
|
| [code]CREATE TABLE t1 ( id INT PRIMARY KEY, title VARCHAR(10))INSERT INTO t1 SELECT 1, 'title 1' UNION ALL SELECT 2, 'title 2' UNION ALL SELECT 3, 'title 3' UNION ALL SELECT 4, 'title 4'-- get PK constraint name SELECT CONSTRAINT_NAME, * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGEWHERE TABLE_NAME = 't1'ALTER TABLE t1 DROP CONSTRAINT ConstraintNameHereDROP TABLE t1[/code]_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-09 : 06:33:05
|
| When you try to drop, it will throw an error message stating that this is used by a foreign key if one exists. You can view all references of this table by usingsp_help <tablename> |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-01-09 : 06:35:57
|
quote: Originally posted by visakh16 When you try to drop, it will throw an error message stating that this is used by a foreign key if one exists. You can view all references of this table by usingsp_help <tablename>
sorry i dont want to drop i just want to disable for certain records ie., for certain period. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-09 : 06:37:45
|
| Didnt understand why you want to disable the primary key on temp table? temp table will be automatically destroyed once you close the connection so cant you change the table structure to remove primary key? May i know what are trying to achieve from this? |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-01-09 : 07:26:55
|
quote: Originally posted by visakh16 Didnt understand why you want to disable the primary key on temp table? temp table will be automatically destroyed once you close the connection so cant you change the table structure to remove primary key? May i know what are trying to achieve from this?
Actually my intention is to know,whether i can disable the primary key constraint on column of a table.ok in case of table what we will do to disable a primary key constraint.plz let me know..... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-09 : 07:52:40
|
quote: Originally posted by raky
quote: Originally posted by visakh16 Didnt understand why you want to disable the primary key on temp table? temp table will be automatically destroyed once you close the connection so cant you change the table structure to remove primary key? May i know what are trying to achieve from this?
Actually my intention is to know,whether i can disable the primary key constraint on column of a table.ok in case of table what we will do to disable a primary key constraint.plz let me know.....
Did you see the example posted?MadhivananFailing to plan is Planning to fail |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-01-09 : 08:13:24
|
quote: Originally posted by madhivanan
quote: Originally posted by raky
quote: Originally posted by visakh16 Didnt understand why you want to disable the primary key on temp table? temp table will be automatically destroyed once you close the connection so cant you change the table structure to remove primary key? May i know what are trying to achieve from this?
Actually my intention is to know,whether i can disable the primary key constraint on column of a table.ok in case of table what we will do to disable a primary key constraint.plz let me know.....
Did you see the example posted?MadhivananFailing to plan is Planning to fail
ya i had seen .i don't want to drop the primary constraint just i want to disable the primary constraint which we will do in case of check constraint (with no check and check options). is it possible in the case of primary constraint ? if possible please let me know how? |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-01-09 : 08:23:27
|
| no you can't disable it. either drop it or not._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-01-09 : 08:29:10
|
quote: Originally posted by spirit1 no you can't disable it. either drop it or not._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
ok thanks for ur replies |
 |
|
|
|