Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

add column between two column Expand / Collapse
Author
Message
Posted Thursday, October 09, 2008 9:57 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, October 10, 2008 5:34 PM
Points: 54, Visits: 221
I have a table having column1,column2,column3,column4

Now I have to modify the table and add two new column column A, ColumnB in between Column1 & Column2.

So new columns list will be column1,column A, ColumnB, column2,column3,column4

How to achieve this using T-SQL?
Post #583437
Posted Thursday, October 09, 2008 10:04 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 9:50 AM
Points: 2,019, Visits: 4,923
bang.prashant (10/9/2008)
I have a table having column1,column2,column3,column4

Now I have to modify the table and add two new column column A, ColumnB in between Column1 & Column2.

So new columns list will be column1,column A, ColumnB, column2,column3,column4

How to achieve this using T-SQL?

You can’t do it. If it is really important for you, you can drop the table and recreate it, but it shouldn’t be important at all. The logical order of the columns is not necessarily the same as the physical order of columns and since you should specify the columns that you want to select clause and not use *, the logical order of columns has no importance at all.

Adi


--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #583445
Posted Thursday, October 09, 2008 10:05 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 11:39 AM
Points: 153, Visits: 235
Not sure if this will help you here is a link to some information.
http://blog.sqlauthority.com/2008/04/08/sql-server-change-order-of-column-in-database-tables/


Respectfully,


K8
Software Developer/Data Analyst
Ozaukee, WI
Post #583447
Posted Thursday, October 09, 2008 8:15 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 32,906, Visits: 26,792
Sure you can do it. And, you don't have to write a lick of T-SQL to do it... Enterprise Manager will write all of the code for you.

Open Enterprise Manager and go into design the table. Make the changes that you want including the inserted columns and then click on the 3rd menu icon from the left (Save Change Script). Follow your nose after that.

Now, SHOULD you do it? That's a whole 'nuther story... ;)


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #583692
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse