I have been working with T-SQL in MS SQL for some time now and somehow whenever I have to insert data into a table I tend to use syntax:
INSERT INTO myTable <something here>
I understand that keyword INTO
is optional here and I do not have to use it but somehow it grew into habit in my case.
My question is:
INSERT
syntax versus INSERT INTO
?If you are using Insert or Insert into both will insert the data in Table. However Insert into is basically used to fatch the data from another table using select command and insert into table where you want to insert the data.
The INSERT INTO statement is used to insert new records in a table.
INSERT INTO SELECT vs SELECT INTO: Both the statements could be used to copy data from one table to another. But INSERT INTO SELECT could be used only if the target table exists whereas SELECT INTO statement could be used even if the target table doesn't exist as it creates the target table if it doesn't exist.
The INSERT INTO Statement in SQL allows you to insert one or more rows into an existing table, either from another existing table, or by specifying the VALUES you want to insert.
INSERT INTO
is the standard. Even though INTO
is optional in most implementations, it's required in a few, so it's a good idea to include it to ensure that your code is portable.
You can find links to several versions of the SQL standard here. I found an HTML version of an older standard here.
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