0

how to drop a primary key with t-sql(i mean script) like alter table tablename modify primary key..! how to write a script to drop a primary key? thanks in advance!!!!

snl
  • 23
  • 1
  • 1
  • 3

1 Answers1

9

To Drop any constraint this is the method

ALTER TABLE Yourtable -- Table Name
DROP CONSTRAINT PK_primarykey_name -- Primary Key name 

If you don't know the primary key constraint name then run the below script to know

SELECT CONSTRAINT_NAME  
FROM   INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE  TABLE_NAME = 'yourtable'  -- Table Name
       AND TABLE_SCHEMA = 'dbo'  -- change it if table is in some other schema 
       AND CONSTRAINT_TYPE = 'PRIMARY KEY' 
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172