MS SQL Server 2005将数据从一个表复制到另一个表

时间:2021-10-29 02:01:39

Hey all, I am trying to find out how to copy data from one table to another database table. I have two connections to two different databases. Ones called comp-DEV1 and the other SQLTEST. I am currently unable to copy data from my sorce table (SQLTEST) to my destination table (comp-DEV1).

嘿所有,我试图找出如何将数据从一个表复制到另一个数据库表。我有两个连接到两个不同的数据库。一个叫做comp-DEV1,另一个是SQLTEST。我目前无法将数据从我的sorce表(SQLTEST)复制到目标表(comp-DEV1)。

This is the error:

这是错误:

Msg 102, Level 15, State 1, Line 2 Incorrect syntax near '-'.

消息102,级别15,状态1,行2' - '附近的语法不正确。

Query:

查询:

 INSERT INTO comp-DEV1.EMSSQL.dbo.tblCL
 SELECT *
 FROM SQLTEST.EMSSQL.dbo.tblCL
 WHERE NOT EXISTS(SELECT * 
             FROM comp-DEV1.EMSSQL.dbo.tblCL 
             WHERE (SQLTEST.EMSSQL.dbo.tblCL.CID = comp-DEV1.EMSSQL.dbo.tblCL.CID)
             )

Any help would be great :o)

任何帮助都会很棒:o)

David

大卫

2 个解决方案

#1


3  

Try wrapping your database names in brackets, such as:

尝试将数据库名称包装在括号中,例如:

INSERT INTO [comp-DEV1].EMSSQL.dbo.tblCL 
 SELECT * 
 FROM SQLTEST.EMSSQL.dbo.tblCL 
 WHERE NOT EXISTS(SELECT *  
             FROM [comp-DEV1].EMSSQL.dbo.tblCL  
             WHERE (SQLTEST.EMSSQL.dbo.tblCL.CID = 
                [comp-DEV1].EMSSQL.dbo.tblCL.CID) 
             ) 

#2


0  

Run the following statement first to check that you can read the source from the destination server:

首先运行以下语句,检查是否可以从目标服务器读取源:

SELECT * FROM [comp-DEV1].EMSSQL.dbo.tblCL

SELECT * FROM [comp-DEV1] .EMSSQL.dbo.tblCL

Get that working first then you should be on your way...

先行,然后你应该在路上......

#1


3  

Try wrapping your database names in brackets, such as:

尝试将数据库名称包装在括号中,例如:

INSERT INTO [comp-DEV1].EMSSQL.dbo.tblCL 
 SELECT * 
 FROM SQLTEST.EMSSQL.dbo.tblCL 
 WHERE NOT EXISTS(SELECT *  
             FROM [comp-DEV1].EMSSQL.dbo.tblCL  
             WHERE (SQLTEST.EMSSQL.dbo.tblCL.CID = 
                [comp-DEV1].EMSSQL.dbo.tblCL.CID) 
             ) 

#2


0  

Run the following statement first to check that you can read the source from the destination server:

首先运行以下语句,检查是否可以从目标服务器读取源:

SELECT * FROM [comp-DEV1].EMSSQL.dbo.tblCL

SELECT * FROM [comp-DEV1] .EMSSQL.dbo.tblCL

Get that working first then you should be on your way...

先行,然后你应该在路上......