Suppose you have initially columns like Col1 and Col3. Now add the column 'Col2' using ALTER query (as above)
This will give you result like: Col1,Col3, Col2
Now I am saying, if you want to get result in the logical order as: Col1,Col2,Col3
you may use your select query like: Select Col1,Col2,Col3 From Table1 Where....
(However physical order of the columns are still 1,3,2 not 1,2,3 but you can get your work done by their Logical order)
You can always set logical order in your 'SELECT' query. If you really interested insert column physically in between two columns, for that I don't have idea and I think, it might not be possible in SQL with ALTER command.
0
Shankar MRank #874 · 2.5K reputationPosted May 17, 2013, 2:53 AM EDT
0
Hi Santhosh,
When you add a column to the Table using ALTER Table method, the column is usually added to the Last only..
And we don't have any direct method to use it ALTER Table method.
And this can be done something like this, Replacing the existing column name to another name and the new column that will be usually added to the Last.
Thanks, Shankar M
0
selva kumarRank #2,987 · 483 reputationPosted May 17, 2013, 5:33 AM EDT
Hemant SrivastavaRank #581 · 4.2K reputationPosted May 11, 2013, 9:05 AM EDT
You want to insert it in between two columns.. but why?
The fact is: Column order you can always set in the query. Right!
For example:
Select Col1, Col2, Col3 FROM Table
OR
SELECT Col1, Col3, Col2 FROM Table
Anyway ALTER query is:
ALTER
TABLE Your_Table
ADD NewlyAdded_Column varchar(50);
Hope this would help you. Let me know if you have any issue.
Santosh YadavRank #6,715 · 258 reputationPosted May 11, 2013, 11:07 PM EDT
Thank you very much for your kind of reply.
Actually this is not the right answer for my question.
My question is that suppose we have two columns in a table col1 and col3. Now we have to insert another column between those two columns.
Col1, Col3
Now add Col2 on the below position :
Col1, Col2, Col3.
Now what would be the appropriate Query ?
Hemant SrivastavaRank #581 · 4.2K reputationPosted May 12, 2013, 6:47 PM EDT
Suppose you have initially columns like Col1 and Col3.
Now add the column 'Col2' using ALTER query (as above)
This will give you result like: Col1,Col3, Col2
Now I am saying, if you want to get result in the logical order as: Col1,Col2,Col3
you may use your select query like: Select Col1,Col2,Col3 From Table1 Where....
(However physical order of the columns are still 1,3,2 not 1,2,3 but you can get your work done by their Logical order)
You can always set logical order in your 'SELECT' query. If you really interested insert column physically in between two columns, for that I don't have idea and I think, it might not be possible in SQL with ALTER command.
Shankar MRank #874 · 2.5K reputationPosted May 17, 2013, 2:53 AM EDT
When you add a column to the Table using ALTER Table method, the column is usually added to the Last only..
And we don't have any direct method to use it ALTER Table method.
And this can be done something like this, Replacing the existing column name to another name and the new column that will be usually added to the Last.
Thanks, Shankar M
selva kumarRank #2,987 · 483 reputationPosted May 17, 2013, 5:33 AM EDT
use these query
Alter Table
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts