Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

column rename

Status
Not open for further replies.

jrprogr

Programmer
Jul 20, 2006
74
US
I want to rename the column name of the table which contains data and also i want to check and replace the column name in the stored procedures(50), views(20) and some triggers. Please suggests me the best way to replace it .

One way is to generate the scripts and find & replace( CTRL H)with old columnname to newcolumn in the script file.

 
You can rename your column with this syntax.

Code:
EXEC sp_rename 
    @objname = 'table.column', 
    @newname = 'NewName', 
    @objtype = 'COLUMN'

You can use the information schema view to find where it's used. For Example I use this one to find column referrences in stored procedures.

Code:
select *
from INFORMATION_SCHEMA.ROUTINES  --INFORMATION_SCHEMA.ROUTINE_COLUMNS
where ROUTINE_TYPE='PROCEDURE'
AND SPECIFIC_NAME like 'usp%' 
AND ROUTINE_DEFINITION like '[b]%MyColumn%[/b]'

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top