Solved

Sql Server Table Column positioning

Posted on 2014-04-02
4
332 Views
Last Modified: 2014-04-02
I added a column to my Sql Server Table by using T-SQL. However, I want to know can I reposition an existing column. In other words, I want to move my column I added to Column 1 position.  Can I do that using T-SQL.?
0
Comment
Question by:metro156
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
Technodweeb earned 500 total points
ID: 39973310
Cannot be done in TSQL...

http://technet.microsoft.com/en-us/library/aa337556.aspx#TsqlProcedure

 To change the column order

This task cannot be performed using Transact-SQL statements.
0
 
LVL 11

Expert Comment

by:Technodweeb
ID: 39973326
I am pretty certain that you must create a new table with the columns in the order you want and then copy the data from the old table to the newly created table. Then drop the old table to make this work.
0
 
LVL 22

Expert Comment

by:Snarf0001
ID: 39973362
In the end it does definitely have to be done by creating a new table, but it's still all going to be through tsql...

You can do this in Management Studio, if you open a table in design view and insert the column, you can hit the button for "Generate Change Script", which will give you the TSQL commands that it's going to run in order to make the change.

Gives you a better idea of what's involved.
0
 
LVL 22

Expert Comment

by:Snarf0001
ID: 39973370
Note that depending on how many indexes / FKs linking to the table, that change script could be huge.  As it's going to have to drop all of the constraints and indexes, transfer the data, and then recreate.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now