Script to drop the primary key

When you do not know the primary key name the following script will be useful to automate. You just need to change the table name and oooollah…

declare @tmp_pk varchar(30),
@tmp_sql varchar(254)
select    @tmp_pk=constraint_name
from information_schema.constraint_table_usage
where table_name='YOUR TABLE NAME'
set @tmp_sql = 'alter table <YOUR TABLE NAME> drop constraint '+ @tmp_pk
print @tmp_sql
exec (@tmp_sql)


1 Comment »

  1. […] Script to drop primary key […]

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: