SQL Get the primary key name/ drop pk/ add pk

SELECT 
	[Name]
FROM [sys].[key_constraints]
WHERE
	[type] = 'PK'
AND
	OBJECT_NAME(parent_object_id) = N'PropertyChannel' 

ALTER TABLE [dbo].[PropertyChannel]
DROP 
    CONSTRAINT [PK_PropertyChannel_ID] 

ALTER TABLE [dbo].[PropertyChannel]
ADD 
    PropertyChannelId int identity(1, 1) NOT NULL

ALTER TABLE [dbo].[PropertyChannel]
ADD
    CONSTRAINT PK_PropertyChannel_ID PRIMARY KEY (PropertyChannelId)

你可能感兴趣的:(Database)