Here’s a quick tip. If you are looking to change the name on all columns in a database, for instance on primary key, you can do it by outputing the next SQL statement to text and then executing the text.
select 'sp_Rename '''+ t.name+'.'+c.name+ ''',''Guid'',''COLUMN'''
from sys.key_constraints as k
join sys.tables as t
on t.object_id = k.parent_object_id
join sys.schemas as s
on s.schema_id = t.schema_id
join sys.index_columns as ic
on ic.object_id = t.object_id
and ic.index_id = k.unique_index_id
join sys.columns as c
on c.object_id = t.object_id
and c.column_id = ic.column_id
where k.type = 'PK';
Quick and simple!
Leave a Comment