开发者

SQL Server insert or query between servers ingnores column in table starting with a number?

I am trying to query between two servers which have identical tables (used the same create statement for both). Whe开发者_如何学运维n I try to insert the results from Server A to Server B I get an error indicating "Column name or number of supplied values does not match table definition."

Query run on server A

Insert into ServerB.Database1.dbo.Table1
Select *
from Table1

The error is clear, but what isn't clear is the reason that it is generated. The definitions of the two tables are identical. What I was finally able to isolate was a table name that starts with a numeric value is not being recognized.

When I run this on ServerA:

Select *
from ServerB.Database1.dbo.Table1

The field with the numeric value is not shown in the results set of they query. The short term fix was to rename the field in the database, but why is this happening?


I am curious about the collation too, but really the answer is to wrap the object names in square brackets. i.e. SELECT [1col], [2col], [etc] FROM [1database].[2owner].[3table]. This way SQL with recognize each as an object name and not a function.

One other thing to keep in mind is to not use splat (*) in your select statement, this has potential problem of it's own. For example, you could run into an error in your Insert if the ServerA's table1 structure was change and ServerB's table one stayed the same.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜