SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


disable primary key constraints in table


disable primary key constraints in table

Author
Message
e1785
e1785
SSC-Enthusiastic
SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)

Group: General Forum Members
Points: 162 Visits: 109
I have a staging database that I use to load up all of my data and see where constraints fail. So I disable constraints using commands like:


ALTER TABLE database.schema.TABLENAME NOCHECK CONSTRAINT MY_CONSTRAINT_NAME;



And then load up my data and run:


DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS;



I would like to be able to do the same thing with primary key constraints but it looks like there isn't an option. Am I missing something?
Meet George Jetson
Meet George Jetson
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3888 Visits: 1398
ALTER TABLE InsertTableName DROP CONSTRAINT PK_Name


To reenable it:
ALTER TABLE InsertTableName ADD CONSTRAINT PK_Name PRIMARY KEY /* CLUSTERED */ (pk_column)

Chris Powell

George: You're kidding.
Elroy: Nope.
George: Then lie to me and say you're kidding.
e1785
e1785
SSC-Enthusiastic
SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)

Group: General Forum Members
Points: 162 Visits: 109
OK. But I take it there's no way to keep it as a "disabled" constraint, as you can with FK checks? The goal is to have the same sort of handy output that I can get with DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS, so I can see the bad data.
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12982 Visits: 4077
e1785 (12/13/2010)
OK. But I take it there's no way to keep it as a "disabled" constraint, as you can with FK checks? The goal is to have the same sort of handy output that I can get with DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS, so I can see the bad data.
see the results
create table textpk 
( id int primary key
)

create table textfk
( id1 int )

ALTER TABLE textfk
ADD CONSTRAINT FK FOREIGN KEY (id1)
REFERENCES textpk (ID) ;


ALTER TABLE textpk
drop CONSTRAINT PK__textpk__27E3AA06



Msg 3725, Level 16, State 0, Line 2
The constraint 'PK__textpk__27E3AA06' is being referenced by table 'textfk', foreign key constraint 'FK'.
Msg 3727, Level 16, State 0, Line 2
Could not drop constraint. See previous errors.
you cant disable PK unless disabling FK first

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search