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
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.
They are the same thing, INTO
is completely optional in T-SQL (other SQL dialects may differ).
Contrary to the other answers, I think it impairs readability to use INTO
.
I think it is a conceptional thing: In my perception, I am not inserting a row into a table named "Customer", but I am inserting a Customer. (This is connected to the fact that I use to name my tables in singular, not plural).
If you follow the first concept, INSERT INTO Customer
would most likely "feel right" for you.
If you follow the second concept, it would most likely be INSERT Customer
for you.
If available use the standard function. Not that you ever need portability for your particular database, but chances are you need portability for your SQL knowledge. A particular nasty T-SQL example is the use of isnull, use coalesce!
I prefer using it. It maintains the same syntax delineation feel and readability as other parts of the SQL language, like group BY
, order BY
.
In SQL Server 2005, you could have something in between INSERT and INTO like this:
INSERT top(5) INTO tTable1 SELECT * FROM tTable2;
Though it works without the INTO, I prefer using INTO for readability.
They both do the same thing. INTO is optional (in SQL Server's T-SQL) but aids readability.