Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Columns Into a Table

Status
Not open for further replies.

VVVA

Technical User
Sep 19, 2006
35
US
How can I use sql to insert columns into a table, and control the order at which they go in the table? I want to insert columns at the beginning of a table, and by default, sql puts them at the end of the table...
 
Build a new version of the table and copy the data into it.

-------------------------
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright
 
A clustered index will control the way data is organized on disk. However, that does not mean that you are assured of returning the data in the same order. To insure that you will return data in the order that you want, you MUST use the "OREDER BY" clause in your query.


- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
Build a new version of the table and copy the data into it.

Well, that's kinda a pain. Oh well, thank you, that's what I'll do!
 
Do not mess with the column order. Add new columns with the alter table command which you can look up in BOL. Changing the column order (by dropping and recreating the table or using enterprise manager which does the same thing) is a bad practice which can result in breaking existing code. Instead of messing with column order you should alwys selct only the columns you want in the order you want them in the results rather than using select *.

Questions about posting. See faq183-874
 
I'm using a program that plugs into existing sql tables, and needs some header columns, and so I can't just modify my queries...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top