472,102 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,102 software developers and data experts.

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 6721
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.