因为我设计的数据库表,里面的主键都是ID,且都是自动增长的,
我在程序中把数据导出后,再导入到新的机器里面,(环境全部部署好,数据库里面是空的数据,是从我们的数据库里面把数据全部手动删除了之后,把文件拷贝出来再附加到新机器里面的。)例如,这个xls文件里面的数据是我需要的,框框里面是需要的ID
但是,我用BCP导入数据之后
变成了这个ID 变了,导致视图里面都没数据了,
数据全部都导入成功!请问该怎么解决这个问题呢?
我在程序中把数据导出后,再导入到新的机器里面,(环境全部部署好,数据库里面是空的数据,是从我们的数据库里面把数据全部手动删除了之后,把文件拷贝出来再附加到新机器里面的。)例如,这个xls文件里面的数据是我需要的,框框里面是需要的ID
但是,我用BCP导入数据之后
变成了这个ID 变了,导致视图里面都没数据了,
数据全部都导入成功!请问该怎么解决这个问题呢?
INSERT INTO.....
SET IDENTITY_INSERT tb OFF--完成之后关闭选项
SET IDENTITY_INSERT tb ON--这样可以把显式值插入表的标识列中。
--bcp
SET IDENTITY_INSERT tb OFF--完成之后关闭选项不过我一般会选择导入到一个临时表,检测数据没问题(如字段长度之类的),在insert 这样不容易出错
bcp代码
SET IDENTITY_INSERT tb off
需要
SET IDENTITY_INSERT tb1,tb2,tb3,tb...tb24 on
bcp代码
SET IDENTITY_INSERT tb1,tb2,tb3,tb...tb24 off这样可以不?
SET IDENTITY_INSERT tb1,tb2,tb3,tb...tb24 on
这样 写可以不、
谢谢~
其实加入 -E这个参数就可以解决了结贴了哈。各位,谢谢。-E
Specifies that identity value or values in the imported data file are to be used for the identity column. If -E is not given, the identity values for this column in the data file being imported are ignored, and SQL Server automatically assigns unique values based on the seed and increment values specified during table creation. If the data file does not contain values for the identity column in the table or view, use a format file to specify that the identity column in the table or view should be skipped when importing data; SQL Server automatically assigns unique values for the column. For more information, see DBCC CHECKIDENT (Transact-SQL).The -E option has a special permissions requirement. For more information, see "Res" later in this topic.