由于需要大量重命名和表的关键性质,我已经能够测试以下脚本来重命名所有约束、索引、触发器、默认值等。因此将创建一个复制脚本,重命名原始文件,然后运行复制脚本:
select o.name as [Name], o1.type as [Type], 'EXEC sp_rename N''' + o1.name + ''', ''' + o1.name + N'_OLD'''
from sys.objects o
inner join sys.objects o1 on o1.parent_object_id = o.object_id
where o.name = 'Product_history'
union
select o.name as [Name], 'I' as [Type], 'EXEC sp_rename N''PRODUCT_HISTORY.' + i.name + ''', ''' + i.name + N'_OLD'''
from sys.objects o
inner join sys.indexes i on i.object_id = o.object_id
where o.name = 'Product_history' and i.name is not null AND i.is_primary_key = 0
order by [Type], [Name]
select o.name as [Name], o1.type as [Type], 'EXEC sp_rename N''' + o1.name + ''', ''' + LEFT(o1.name,LEN(o1.name)-4) + N''''
from sys.objects o
inner join sys.objects o1 on o1.parent_object_id = o.object_id
where o.name = 'Product_history'
union
select o.name as [Name], 'I' as [Type], 'EXEC sp_rename N''PRODUCT_HISTORY.' + i.name + ''', ''' + LEFT(i.name,LEN(i.name)-4) + N''''
from sys.objects o
inner join sys.indexes i on i.object_id = o.object_id
where o.name = 'Product_history' and i.name is not null AND i.is_primary_key = 0
order by [Type], [Name]