Solved

Sql Server Table Column positioning

Posted on 2014-04-02
4
337 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

690 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