question

baijumohan avatar image
baijumohan asked

Table alias ignored for columns specified in INSERT statement in SQL Server

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. 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?
sql-servertsqlsql serverinsert
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

This is not an answer, but when we upgraded one of our databases from 2005 to 2014 some of the syntax in some of the stored procedures started throwing errors where they previously had not. Turns out there were phantom aliases like you describe only they were in ORDER BY clauses. Could just be an oversight that the developers have tightened up. What version of SQL Server have you noticed this in?
0 Likes 0 ·
we are using sql-server 2012
0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.