Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Add new columns in between of existing columns

Author  Topic 

goodman2253
Yak Posting Veteran

88 Posts

Posted - 2012-07-10 : 08:21:27
Is it possible to add new columns in between of existing columns

There exist a table named total_code.
which contains the columns as in sequence
A B C D E

I want to add new column A1 and want that it should come and add like
A A1 B C D E

Thanks.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-07-10 : 08:24:36
The sequence of columns in a table isn't important because you can change the order in the column list of your select statement.
The only way to get what you want - if you really want it - is to recreate the complete table.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-07-10 : 08:30:53
it's one of the tenants of a relational design. intrinsic order of rows or columns should never be important.

Of course when the engine lets you issue statements like:

INSERT tbFoo
SELECT a, b, c, d

Rather than

INSERT tbFoo ([colA], [colC], [colD], [colb])
SELECT a, b, c, d

Then it's easy for a lazy / ignorant coder to save up problems for the future.

Transact Charlie

Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-07-10 : 08:31:40
and obviously.... avoid
SELECT *
in any prod code.....

Transact Charlie

Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
Go to Top of Page
   

- Advertisement -