--删除主键
Declare @Pk varChar(100);
Select @Pk=Name from sysobjects where Parent_Obj=OBJECT_ID('ImportRecords') and xtype='PK';
if @Pk is not null
begin
exec('Alter table ImportRecords Drop '+ @Pk) --删除原主键
end
--创建一个普通列
ALTER TABLE dbo.ImportRecords ADD ImportID0 nvarchar(50)
GO
--将自增列数据插入新建列名中
UPDATE dbo.ImportRecords SET ImportID0 = ImportID;
GO
--删除自增列
ALTER TABLE dbo.ImportRecords DROP COLUMN ImportID
GO
--修改增加的列名为自增列的列明
EXEC sys.sp_rename @objname = N'ImportRecords.ImportID0',
@newname = 'ImportID',
@objtype = 'COLUMN'