Solved

Sql Server Table Column positioning

Posted on 2014-04-02
4
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
Gregory Miller 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:Gregory Miller
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 23

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 23

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio Debugging 3 164
Access 2013: API code to put hidden database icon in taskbar? 8 106
Best book to learn C++ 4 96
PL SQL Developer 7 90
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…

732 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