.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

Add Column in a table

Posted By: Santosh     Posted Date: October 28, 2010    Points:2   Category :Sql Server
Hi All,

Is it possible to add a column in existing table in any position....


Regards
Santosh

Responses
Author: Dhivakaran             
Posted Date: October 28, 2010     Points: 5   

yes, You can add new column in any position at design layaout.

for that you just need to right click anyone of column and then select "Insert column" option

-
Dhivakaran T
Author: Santosh             
Posted Date: October 28, 2010     Points: 5   

Hi Dhivakaran

i know in design layaout....
i want to do it through query....



Regards
Santosh

Author: Asha.MP             
Posted Date: October 28, 2010     Points: 5   

Hi..

You can use alter command to add the table like

Alter Table TableName
add ColumnName ColumnDataType

Thanks and Regards,
Asha.mp
Author: Santosh             
Posted Date: October 29, 2010     Points: 5   

Hi Asha.MP ,

This Command will add the column at the end of the table , but i want to add it in middle position...

can u give me the example for this....



Rehards
Santosh

Author: Ramesh P             
Posted Date: October 29, 2010     Points: 5   

Hi santosh,

Don't worry for that. It is possible to add a column in any position.
There are two Method.

Method 1:
For that, Insert values from your existing "YourTable" to this "New_YourTable". Drop the existing table "YourTable" and rename "New_YourTable" to "YourTable". This is again resource consuming exercise along with chance of getting something wrong if this is heavily used production server.

Method 2:
you can create view on the base table with your desired column order.


Regards,


Ramesh

Author: Ramesh P             
Posted Date: October 29, 2010     Points: 5   

Please don't forget to mark as answer.

Regards,


Ramesh

Author: Deco             
Posted Date: October 29, 2010     Points: 5   

Santosh,

if you want to keep the column ordinal position you need to do it through the Enterprise Manager

Through Query, You can do, but it will create a complex move to get it done.


You need to get the script of the table.

then have to take the back up of the table.

then you have to add a column in the script and can fix the position

then you need to execute the table script and have to load the data from the

backup table into the table you have created through script.

why to have unnecessary run around, please change it in the design mode :-)

Regards,
Deco


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend