Why does not the following INSERT
statement give any error?
CREATE TABLE Table1(id INT,name VARCHAR(10))
INSERT INTO Table1(xx.id,yyyy.name) Values (1,'A')
Why does the above statement ignore xx.
and yyyy.
? What does this imply ?
Use the context menu on the same table, to get another script: "Script Table as | SELECT To | New Query Window". This will be a totally standard select list, with all your fields listed out. Copy the whole query and paste it in over the VALUES clause in your first query window. This will give you a complete INSERT ...
Note − Use the INSERT IGNORE command rather than the INSERT command. If a record doesn't duplicate an existing record, then MySQL inserts it as usual. If the record is a duplicate, then the IGNORE keyword tells MySQL to discard it silently without generating an error.
I checked the below query also.
INSERT INTO Table11(xx.xx.xx.xx.xx.xx.xx.id,yy.yy.yy.yy.yy.yy.yy.yy.name)
Values (1,'A')
It also got worked. Usually we use alias for joins. As I know, For Insert query Using alias near table name is restricted in sql. In the case of column name, the query use only the string next to the last Dot(.).
I conclude it as, The Insert query don't care about the string prefixed to the column name separated by Dot(.).
The only thing I can think of is that the database engine is ignoring the name space as the query's scope is limited to the Table's scope when dealing with INSERT INTO. When it comes to say UPDATE where multiple tables can be part of the scope, the below would fail. Don't know why this happens but if I were to guess, probably all values to the left of the last period'.' is ignored
If you analyze the execution plan for the below query
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With