【SqlServer】------- SqlServer 修改主键字段大小示例代码

declare @pkName varchar(50)

SELECT @pkName=CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='DCS_WEIXIN_POST_MESSAGE'
 
 EXEC('
ALTER TABLE dbo.DCS_WEIXIN_POST_MESSAGE
DROP CONSTRAINT '+@pkName)



alter table DCS_WEIXIN_POST_MESSAGE alter column ID VARCHAR(50)  not null

 EXEC('
ALTER TABLE dbo.DCS_WEIXIN_POST_MESSAGE ADD CONSTRAINT
'+@pkName+' PRIMARY KEY CLUSTERED 
(
ID
)ON [PRIMARY]
')

 

你可能感兴趣的:(sqlserver)