Two forms of an insert statement. Are both equivalent, and acceptable?

I am working with a stored procedure that is used about four times per year to update a table in the database. Basically the script contains a bunch of insert statements that insert data into a particular Oracle table. Now when I write insert statements I like to list out all of the column names and values being inserted into a column. See line #1 below. I noticed that the last time the script was updated by a former team member that instead of listing out all of the column names for the insert, that they use a SELECT dual statement to select data into the table; see line #2. So (Question 1) are both insert statements acceptable? If so then is one method better than the other? (Question 2).



#1 INSERT INTO CUSTOMER (ID,FirstName,LastName) VALUES (109, 'Joe','Smith');

#2 INSERT INTO CUSTOMER SELECT 109,'Joe','Smith' FROM DUAL;
LVL 2
brgdotnetcontractorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

schwertnerCommented:
They both will insert one row in the table.
There is a small difference between them.
In the first one you declare the columns - (ID,FirstName,LastName)
In the second one the declaration of the columns is missing and in some cases this can cause errors.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
To compare them, you should address the column list order problem:

Either

#1 INSERT INTO CUSTOMER VALUES (109, 'Joe','Smith');
#2 INSERT INTO CUSTOMER  SELECT 109,'Joe','Smith' FROM DUAL;

or

#1 INSERT INTO CUSTOMER (ID,FirstName,LastName) VALUES (109, 'Joe','Smith');
#2 INSERT INTO CUSTOMER (ID,FirstName,LastName) SELECT 109,'Joe','Smith' FROM DUAL;

In both cases the second is more text to type. And while not physically possible, but logical, the second query may insert nothing or too much. A table may be empty or return more than one row.

Imho the second style is coding bad style.
0
brgdotnetcontractorAuthor Commented:
Thanks guys. I gave schwertner more points because he answered first.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.