11

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

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?

bmsqldev
  • 2,627
  • 10
  • 31
  • 65
  • 4
    Interesting. Quick guess it could use `exposed names` in column list and ignores the rest. More info [here](http://stackoverflow.com/questions/33424988/sql-server-object-names/33425543#33425543) and [here](https://blogs.msdn.microsoft.com/ialonso/2007/12/21/msg-1013-the-object-s-and-s-in-the-from-clause-have-the-same-exposed-names-use-correlation-names-to-distinguish-them/) – Lukasz Szozda Mar 11 '16 at 09:48
  • 4
    Interesting, I'm not seeing anything in the documentation that would allow those qualifiers. – TT. Mar 11 '16 at 10:01
  • @lad2025. Thanks for the links. But it seems Exposed Names are related to table names not the column – bmsqldev Mar 11 '16 at 11:17

1 Answers1

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.

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 "".

  • you mean [a.a.a.value1] or "a.a.a.value1" . Both will give invalid column error – bmsqldev Mar 11 '16 at 13:29
  • Yes, because you would have to create columns with such names - otherwise those columns doesn't exist. –  Mar 11 '16 at 14:33