The following code has been found on the Internet:
DECLARE @Pk varchar (100);
Select @Pk =name from sysobjects where parent_obj=object_id (' table name ') and xtype= ' Pk ';
If @Pk is not null
Begin
EXEC (' Alter table name Drop ' + @Pk)--Delete the primary key
End
The point here is that the table Sysobjects,sysobjects table is a system table, each object created in the database (constraints, defaults, logs, rules, stored procedures, etc.) in the table for a row, the above xtype is the type, such as PK is the primary key, F is a foreign key, that is, Delete the foreign key, you just need to change the PK to F can be, the same as the default constraints D and so on.
EXEC (' SQL statement ') is a stored procedure that executes SQL statements
In fact, the use of good sysobjects this table, we can make a lot of articles, such as looking at an object (table, database, stored procedures, etc.) exist.
SQL Server removes the primary key constraint that is thought of