By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,378 Members | 1,435 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,378 IT Pros & Developers. It's quick & easy.

Change order of column in SQL 2005

P: 17
Hi to all

I have a table having three column. I add one column at run time and client requirement is that this added column should be first column.

How i can make this as a first column

Thanks to all
Mar 25 '08 #1
Share this Question
Share on Google+
6 Replies


vksingh24
P: 21
Hi to all

I have a table having three column. I add one column at run time and client requirement is that this added column should be first column.

How i can make this as a first column

Thanks to all

I am not sure but you can use the column name which you have added at run time as the first column in your SELECT Statement
Mar 25 '08 #2

ck9663
Expert 2.5K+
P: 2,878
Create a function or a view. Or simply, on your extract, do a

Expand|Select|Wrap|Line Numbers
  1. SELECT Col4, Col1, Col2, Col3 from YourTable
-- CK
Mar 25 '08 #3

P: 17
I am not sure but you can use the column name which you have added at run time as the first column in your SELECT Statement
Thanks for reply

But actually the problem is that
I have a table which contain identity column
When i delete some data i.e. row from table then sedquence will break
(1,2,3,7,8) Identity column have these value we have to make this like (1,2,3,4,5)

How i can
Mar 27 '08 #4

P: 17
Create a function or a view. Or simply, on your extract, do a

Expand|Select|Wrap|Line Numbers
  1. SELECT Col4, Col1, Col2, Col3 from YourTable
-- CK


Thanls foe reply

I am not creating table at run time i have to update the idemtity column at run time
Mar 27 '08 #5

ck9663
Expert 2.5K+
P: 2,878
You can't. Identity columns are read-only. I think you can reset it, but if you use that as PK/FK, your table relationship will be affected.

-- CK
Mar 27 '08 #6

Delerna
Expert 100+
P: 1,134
I don't have SQL 2005 so I don't know the correct syntax but Sql server 2005 has a function that returns the row number.
So you could use that to achieve what you need.
In your example the identity field will be 1,2,3,7,8
but the field that returns the row number will be 1,2,3,4,5
You will obviously need to sort the records by the indentity field so that the row numbers will be correct.
Mar 28 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.