--做前自己先备份一下数据
select * into #temp from 表 order by 编号
ALTER TABLE 表 DROP COLUMN 编号
ALTER TABLE 表 ADD 编号 bigint identity(1,1) not null
truncate table 表
SET IDENTITY_INSERT 表 ON
insert 表(编号,col1,col2,...) select 编号,col1,col2,... from #temp
SET IDENTITY_INSERT 表 OFF
drop table #temp
select * into #temp from 表 order by 编号
ALTER TABLE 表 DROP COLUMN 编号
ALTER TABLE 表 ADD 编号 bigint identity(1,1) not null
truncate table 表
SET IDENTITY_INSERT 表 ON
insert 表(编号,col1,col2,...) select 编号,col1,col2,... from #temp
SET IDENTITY_INSERT 表 OFF
drop table #temp
假如级联删除的话,明细数据都没有了
那保留编号值,还有什么用?
go
ALTER TABLE 表 DROP COLUMN 编号
go
ALTER TABLE 表 ADD 编号 bigint identity(1,1) not null
go
truncate table 表
go
SET IDENTITY_INSERT 表 ON
insert 表(编号,col1,col2,...) select 编号,col1,col2,... from #temp
SET IDENTITY_INSERT 表 OFF
go
drop table #temp
如何用语句添加或去除表字段的自增属性
http://expert.csdn.net/Expert/topic/2217/2217137.xml?temp=.8302118
你应该能在本地注册新网上的数据库实例吧
步骤:
SQlserver企业管理器-->右键SQlserver组-->新建sqlserver注册-->下一步-->写入远程实例名(IP,机器名)-->下一步-->选Sqlserver登陆-->下一步-->写入登陆名与密码(sa,pass)-->下一步-->下一步-->完成
注册好了之后,你就可以用企业管理器设计表的功能,把那个字段选为标识。
--增加标识的方法
SQL SERVER企业管理器-->右键你的表-->设计表-->选中你要设置标识的字段(必须是int类型)-->下面有个属性叫“标识”的,选“是”,你可以按你的要求改一下标识种子或标识递增量,然后保存该表的设计。