March 6, 2006 at 4:32 am
Is it possible to use a stored procedure to rename a column name in a table without losing the data held within it?
March 6, 2006 at 5:30 am
I've found this by searching this forum,
exec sp_rename 'dbo.TableName.newcol','OldCol','COLUMN'
what I'd like to do is make a Stored procedure that I can pass in TableName, oldcolumn, newColumn. So it needs to be done dynamically
March 6, 2006 at 7:28 am
you can create a procedure that uses sp_rename...something like this:
create procedure sp_ChangeColumnName @table_name varchar(50), @old_name varchar(50), @new_name varchar(50) as declare @sql varchar(150) set @sql = 'sp_rename "' + @table_name + '.' + @old_name + '", "' + @new_name + '", "' + 'column"' exec(@sql) Then execute this by passing the parameters... exec sp_ChangeColumnName 'table_name', 'old_name', 'new_name'
**ASCII stupid question, get a stupid ANSI !!!**
March 7, 2006 at 2:31 am
Go to Enterprise Manager,select database, select the table name and select the column name right click select design table. You can change what ever you want. Ok....
Ramaa
March 7, 2006 at 2:52 am
many thanks Rama, that's helped a great deal
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy