日期:2014-05-18  浏览次数:20455 次

自动增长列问题
sql server2005在导出表时 表的主键和自动增长列会自动消失 如果使用编辑SQL导出表中数据的所有自动增长id会重新排列 现在表中的自动增长列数据是不连贯的 怎样才能把数据原样导出而且该列还是自动增长列呢 或则能实现这样效果的其他方法

数据库是要导出到虚拟空间上的 导出到虚拟空间后就不可以对数据库在进行修改的操作了 

在线等答案 急 急 急

------解决方案--------------------
把identity关闭
------解决方案--------------------
SQL code

--====1建立链接服务器,确保你本机可以访问到虚拟空间

exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

--创建链接服务器 
exec sp_addlinkedserver   'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 ' 
exec sp_addlinkedsrvlogin 'ITSV ', 'false ',null, '用户名 ', '密码 ' 

--====2在链接服务器的库上操作!

set identity_insert ITSV.[xsd].dbo.[xsd_webContentZ] on

insert into ITSV.xsd.dbo.xsd_webContentZ(webConZ_id,..) --插入的字段都写出来,注意一定要写自增列
select *
from xsd_webContentZ  --本地表

set identity_insert ITSV.[xsd].dbo.[xsd_webContentZ] off

--====3删除链接服务器

exec sp_dropserver  'ITSV ', 'droplogins ' 

exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure