469,345 Members | 6,252 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,345 developers. It's quick & easy.

SQL 2000 renaming columns in tables

19
This code works in query analyzer to rename one column in a table, can someone please give me the script to rename more than one column in a table and along with that, I need to change the data type (length) while I'm at it.

sp_rename 'medicaid.col001', 'id', 'COLUMN'
Mar 10 '07 #1
2 6603
bergy
89
This code works in query analyzer to rename one column in a table, can someone please give me the script to rename more than one column in a table and along with that, I need to change the data type (length) while I'm at it.

sp_rename 'medicaid.col001', 'id', 'COLUMN'
I usually rename and modify data types like so:

Change Datatypes:
ALTER TABLE table_name ALTER COLUMN some_column varchar(100);

Change Column Name:
ALTER TABLE table_name RENAME COLUMN old_name to new_name;

I know it's not all in one query to the DB but maybe you could make a procedure to take care of it? Or if you're doing this in an application it shouldn't matter.
Mar 11 '07 #2
kbaisch
19
I usually rename and modify data types like so:

Change Datatypes:
ALTER TABLE table_name ALTER COLUMN some_column varchar(100);

Change Column Name:
ALTER TABLE table_name RENAME COLUMN old_name to new_name;

I know it's not all in one query to the DB but maybe you could make a procedure to take care of it? Or if you're doing this in an application it shouldn't matter.
Thanks Bergy, I'll give it a try.
Mar 12 '07 #3

Post your reply

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

Similar topics

1 post views Thread by Trevor Jackson | last post: by
1 post views Thread by Don Leverton | last post: by
6 posts views Thread by Peter Frost | last post: by
8 posts views Thread by BillCo | last post: by
2 posts views Thread by Ilyas | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.