sql08 语句修改标识列数据

  昨天给客户导数据,内容表38万条记录,表字段不到100个。用程序分批导。

由于标识列 id 里的值有用,所以在导入时把id改为了不自增。导完后,再加为自增列时,提示超时。

用语句 alter table rcms_contents alter column [id] bigint identity(1,1) 修改,在sql08下提示语法错误。

于是找高手,上网查,解决了。方法如下:

  1、先把数据加到临时表里,一会儿会用到 select * into #content from content

  2、先加一列id_1设为自增列 alter table rcms_Contents add id_1 bigint identity(1,1)

  3、(一定要备份数据库)然后把正表里的数据删掉 truncate table content

  4、打开此表设计,把id列改为自增,保存表

  5、执行 set identity_insert content on (可更改标识列)

  6、用 insert into 字段 select 字段 from #content 从临时表里进行导入数据

  7、把可更改标识列的值关闭,执行 set identity_insert content off

其中第二步可以不执行

这样就大功告成了。数据库方面还要再加强。

原文地址:https://www.cnblogs.com/beidao/p/3256888.html