SQL Server: Insert INTO Statement Syntax

Why shouldn't I run the following INSERT ?

 CREATE TABLE Table1(id INT,name VARCHAR(10)) INSERT INTO Table1(xx.id,yyyy.name) Values (1,'A') 

Why the above statement ignores xx. and yyyy. ? What does this mean?

+6
source share
4 answers

I also checked below request.

 INSERT INTO Table11(xx.xx.xx.xx.xx.xx.xx.id,yy.yy.yy.yy.yy.yy.yy.yy.name) Values (1,'A') 

He also worked. Usually we use an alias for joins. As I know, for the Insert request, the use of an alias next to the table name is limited in sql. For a column name, the query uses only the row next to the last dot (.).

I conclude this as a The Insert query, do not care about the row prefixed with the name of the column separated by dot Dot (.).

+1
source

This implies the namespace of something ...

For instance:

 SELECT object.id, object.name FROM table object WHERE object.name = 'Foo'; / \ | | object is the name space for the table. 

And if you don't have a namespace created, the request failed.

0
source

The only thing I can think of is that the database engine ignores the namespace, since the query area is limited to the table area when working with INSERT INTO. When it comes to the UPDATE message, where several tables may be part of the scope, there will be an error below. I don’t know why this is happening, but if I have to guess, probably all the values ​​to the left of the last period. "

If you analyze the execution plan of the request below

 CREATE TABLE Table1(id INT,name VARCHAR(10)) INSERT INTO Table1(Table2.dbo.id,...................name) Values (1,'A') 

As

 INSERT INTO [Table1]([id],[name]) Values(@1,@2) 
0
source

As far as I know, the syntax you use usually means table.column Thus, in other words, you are trying to insert into table 1, but declare columns from other tables.

You should do something like this

 CREATE TABLE Table1(id INT,name VARCHAR(10)) INSERT INTO Table1(id,name) Values (1,'A') 
-1
source

Source: https://habr.com/ru/post/977828/


All Articles