跨库复制表数据,有很多种方法,最常见的是写程序来批量导入数据了,但是这种方法并不是最优方法,今天就用到了一个很犀利的方法,可以完美在 Sql Server 2005 和 Sql Server 2008 中执行!
格式如下:
insert into tableA
SELECT * FROM
OPENDATASOURCE('SQLOLEDB', 'Data Source=127.0.0.1;User ID=sa;Password=sasasa').databaseName.dbo.tableB
找到这个方法后,准备执行,可是却并不太顺利,跨库复制表数据的途中,接连出现两个错误,第一个错误:
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
翻译:
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的
STATEMENT'OpenRowset/OpenDatasource'
的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc
Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL
Server 联机丛书中的 "外围应用配置器"。
错误2 :
An explicit value for the identity column in table 'cms_TagSubject' can only be specified when a column list is used and IDENTITY_INSERT is ON.
这个真的很纠结,没办法,只有 google 了,之后发现可以 在执行的 SQL 语句前后加上:
SET IDENTITY_INSERT tableA ON
--执行的SQL
SET IDENTITY_INSERT tableB ON