表别名忽略了SQL Server中INSERT语句中指定的列

时间:2020-11-29 22:25:44

I have seen above question in one of the blogs. But couldn't find the answer anywhere. Maybe SQL Server experts here can help me on this.

我在其中一个博客上看到过这个问题。但是到处都找不到答案。也许这里的SQL Server专家可以帮助我解决这个问题。

CREATE TABLE #DEMO (VALUE1 INT, VALUE2 VARCHAR(10))

CREATE TABLE #DEMO1 (VALUE1 INT, VALUE2 VARCHAR(10))

INSERT INTO #DEMO VALUES (1, '10')

INSERT INTO #DEMO1 (a.a.a.value1,b.b.b.value2)
    SELECT
        Value1, Value2
    FROM #DEMO

If you see the insert statement, I have specified some alias name in the inserted columns. To my wonder, SQL Server didn't throw any error while executing the statement. What's the reason behind this? Could anyone help?

如果您看到insert语句,我已经在插入的列中指定了一些别名。令我惊奇的是,SQL Server在执行语句时没有抛出任何错误。这背后的原因是什么?有人能帮忙吗?

1 个解决方案

#1


1  

List of column names in this place is list of names in #DEMO1 table therefore qualifiers doesn't have any meaning and most likely are just ignored.

这里的列名列表是#DEMO1表中的名称列表,因此限定符没有任何意义,很可能被忽略。

It is interesting why it doesn't rise syntax error, either way if you would want to use columns names as a.a.a.value1 then you would have to put name in [] or "".

有趣的是,如果您希望将列名用作a.a.a.,那么它为什么不会引起语法错误呢?value1则必须在[]或"" "中输入名称。

#1


1  

List of column names in this place is list of names in #DEMO1 table therefore qualifiers doesn't have any meaning and most likely are just ignored.

这里的列名列表是#DEMO1表中的名称列表,因此限定符没有任何意义,很可能被忽略。

It is interesting why it doesn't rise syntax error, either way if you would want to use columns names as a.a.a.value1 then you would have to put name in [] or "".

有趣的是,如果您希望将列名用作a.a.a.,那么它为什么不会引起语法错误呢?value1则必须在[]或"" "中输入名称。