Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Plz let me know ........

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 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

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 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out



how????
Go to Top of Page

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_USAGE
WHERE TABLE_NAME = 't1'

ALTER TABLE t1 DROP CONSTRAINT ConstraintNameHere

DROP TABLE t1
[/code]

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

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 using

sp_help <tablename>
Go to Top of Page

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 using

sp_help <tablename>




sorry i dont want to drop i just want to disable for certain records ie., for certain period.
Go to Top of Page

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?
Go to Top of Page

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.....

Go to Top of Page

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?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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?

Madhivanan

Failing 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?
Go to Top of Page

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 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

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 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out



ok thanks for ur replies
Go to Top of Page
   

- Advertisement -