2
我有两个数据库有相同的表。 DBProduction和DBLocal都有testTable。我怎样才能用DBLocal替换DBProduction的testTable?插入了一些新行,并在DBLocal的testTable中更新了一些行。用另一个数据库替换一个数据库的表
使用SQL Server 2008
我有两个数据库有相同的表。 DBProduction和DBLocal都有testTable。我怎样才能用DBLocal替换DBProduction的testTable?插入了一些新行,并在DBLocal的testTable中更新了一些行。用另一个数据库替换一个数据库的表
使用SQL Server 2008
如果他们是在同一台服务器上,并且具有相同的表结构,你可以这样做:
Truncate Table DBProduction.dbo.testTable
Go
Insert Into DBProduction.dbo.testTable
Select * From DBLocal.dbo.testTable
如果它们是在不同的服务器,你可以运行截断声明如上所示,然后右键单击DBProduction并选择导入数据。这将启动向导并为您导入数据。
编辑: 我还应该补充说,如果表结构不同,你应该Drop Table DBProduction.dbo.testTable
,然后使用导入数据向导导入(并且默认重新创建)DBProduction中的testTable。
编辑2:
如果你想插入(没有列出所有列)将列设置为标识,你需要做到以下几点:
Set Identity_Insert DBProduction.dbo.testTable On
Insert Into DBProduction.dbo.testTable
Select * From DBLocal.dbo.testTable
Set Identity_Insert DBProduction.dbo.testTable Off
这将暂时忽略身份播种。
HTH
巴里
需要列出列名,否则提示错误:表“DBProduction.dbo.testTable”的标识列的显式值时,使用的列清单,才能指定和IDENTITY_INSERT已打开。 – coure2011 2010-04-23 07:15:11