Click here to Skip to main content
15,918,007 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What SQL structure allows you to specify the columns/values for an INSERT statement in a different order than that in which they appear in the table?

Choice 1
SQL
The ORDER BY clause

Choice 2
SQL
The values list, as in "INSERT INTO employees VALUES (24, 'Smith', 'Barney')"

Choice 3
SQL
The column list, as in "INSERT INTO employees (emp_id, last_name, first_name)"

Choice 4
SQL
The ALTER TABLE statement

Choice 5
SQL
The SET statement

I am not getting the question itself.
Does that mean -
select a structure which will let you select the different order for INSERT statement ?
Posted
Updated 28-Nov-13 6:18am
v3
Comments
phil.o 28-Nov-13 11:10am    
In the question, you can replace 'What SQL structure' with 'Among five following choices, which one'.
agent_kruger 29-Nov-13 2:28am    
i dont get the question please reframe it?

Perhaps explaining the question another way might help ...

Imagine you have created a table like this
SQL
CREATE TABLE MyTable
(
	COLUMN1 Varchar(15),
	COLUMN2 Varchar(20),
	COLUMN3 Varchar(3)
) 
and you want to put some data into it so that it ends up like this ...
COLUMN1		COLUMN2		COLUMN3
3		2		1	

But you want to pass the data to your insert query in your own order of
1, 2, 3
(NOT 3, 2, 1 as per the illustration above)

The question is asking you which of the 5 options would you use to do the insert in that order.

You were not far away with your interpretation of the question, but I would avoid the word "structure" - it is misleading. Better wording of the question would have been
Quote:
select a sql construct which will let you select the different order for INSERT statement
 
Share this answer
 
Comments
Swap9 28-Nov-13 11:52am    
Yes I got it now. Thank you so much. but what construct would do that in SQL ?

Choice 1
The ORDER BY clause
Choice 2
The values list, as in "INSERT INTO employees VALUES (24, 'Smith', 'Barney')"
Choice 3
The column list, as in "INSERT INTO employees (emp_id, last_name, first_name)"
Choice 4
The ALTER TABLE statement
Choice 5
The SET statement
CHill60 28-Nov-13 12:19pm    
As phil.o said ... we don't do your homework for you - for your own benefit, not because we're cruel :-). What I can do for you is tell you if you are right if you have a go at answering this yourself. Here is a link that might help with your research http://technet.microsoft.com/en-us/library/dd776381(v=sql.105).aspx[^]
Maciej Los 28-Nov-13 14:50pm    
Well explained, a 5!
Swap9 28-Nov-13 23:06pm    
Thanks for that.
I picked choice 3 based on my research.
CHill60 30-Nov-13 8:02am    
Well done. That is the correct choice
Simple:
SQL
INSERT INTO [Table] ([IntColumn], [NVarcharColumn]) VALUES (1, N'text')

could be done this way:
SQL
INSERT INTO [Table] ([NVarcharColumn], [IntColumn]) VALUES (N'text', 1)
 
Share this answer
 
v3
Comments
Swap9 28-Nov-13 10:49am    
I dont think so. I have to pick any of these choice -

Choice 1
The ORDER BY clause
Choice 2
The values list, as in "INSERT INTO employees VALUES (24, 'Smith', 'Barney')"
Choice 3
The column list, as in "INSERT INTO employees (emp_id, last_name, first_name)"
Choice 4
The ALTER TABLE statement
Choice 5
The SET statement
phil.o 28-Nov-13 10:57am    
You don't think so?
It's homework, so please take the time to analyze carefully what has been told to you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900