开发者

how to import data from other database in SQL Server 2005

I have 2 databases in SQL Server 2005. I want a functionality that i have same table structure in 2 database for example i have a same table named as 开发者_如何学运维testData in 2 database named as dbTest1 and dbTest2.

Now i want a single query through which i can add all the records from table testData of database dbTest2 into table testData of database dbTest1.

I tried to use following query

insert into dbTest1.testData values select * from dbTest2.testData

but this query is not running and giving error.

I also tried

insert into dbTest1.testData(col1,col2,col3) values select * from dbTest2.testData but this also gives error that "Invalid object name dbTest2.testData"

Could any one help in this

Thanks


Replace dbTest2.testData with dbTest2..testData - you have to specify 3 things (or optionally leave the middle blank for dbo).

i.e.

insert into dbTest1..testData
select * from dbTest2..testData

If the table doesn't already exist in dbTest1, you can do this:

select * 
into dbTest1..testData
from dbTest2..testData


You need to specify all column names in query.

insert into dbTest1.dbo.testData(col1,col2,col3) select * from dbTest2.dbo.testData
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜