一表caipiao,列为F1 char(10),F2 char(2),F3 char(2) 想通过代码把F1这个字段改成bigint类型且为自动增长列,我的代码如下但是总有问题,请问错哪里了? alter table caipiao alter column F1 bigint identity(2010058,1)
identity只对数值型有效Alter table caipiao drop column F1Alter table caipiao add F1 int Identity(2010058,1) GO
alter table caipiao add F1 int identity(2010058,1) GO
--新增加一列在增长列 Alter table caipiao add F4 int Identity(2010058,1) --变成可更改类型 SET IDENTITY_INSERT caipiao ON --把原有值替换 update caipiao set F4=F1 --改回原有设置 SET IDENTITY_INSERT caipiao OFF Alter table caipiao drop column F1 go exec sp_rename 'caipiao.F4' ,'F1', 'column'
GO
GO
Alter table caipiao add F4 int Identity(2010058,1)
--变成可更改类型
SET IDENTITY_INSERT caipiao ON
--把原有值替换
update caipiao set F4=F1
--改回原有设置
SET IDENTITY_INSERT caipiao OFF
Alter table caipiao drop column F1
go
exec sp_rename 'caipiao.F4' ,'F1', 'column'