KESAVAN PURUSOTHAMAN
KESAVAN PURUSOTHAMAN

Reputation: 453

How to reorder and add columns on specific position in SQL Server 2008 R2?

I wants to build the tool to reorder the fields of already exist table with data in SQL Sever 2008 R2. Also I want to create a logic to add a column in any specific position. In Mysql or firebird they have the options and TSQL queries to do that.Any body please share whether we have that options in SQL Sever 2008 R2. If any smart logic available means share it to me. Thanks in advance.

Upvotes: 0

Views: 12750

Answers (1)

PseudoToad
PseudoToad

Reputation: 1574

Re-ordering the columns of an existing table is going to be a costly process. The table will have to be rebuilt from scratch. SQL does this for you by creating a copy of the table using the new order and then inserting the existing data into that table. Once this is done, the initial table is dropped and the new one put back in place.

A better solution would be to use a VIEW. They can be changed at will.

Upvotes: 2

Related Questions