从网上下了一个系统,要想把数据库和项目中用到的整合到一起,不过会有重名发生
想把所有表都加上一个前缀,不过一个一个改又麻烦.就写了这个东西
declare curRt cursor
for
select [name] from sysobjects where xtype = 'U' and [name]<> 'dtproperties'
declare @tn nvarchar(20),@sql nvarchar(2000)
open curRt
fetch curRt into @tn
while @@fetch_status =0
begin
select @sql = N'exec sp_rename ''' + @tn + ''', ''thr_' + @tn +''',''OBJECT''' ---这里加的前缀为thr_
execute @sql
fetch next from curRt into @tn
end
close curRt
deallocate curRt
sp_rename和execute功能都很强大很有帮助
希望大家多交流。共同进步
本文介绍了一种使用T-SQL脚本批量修改数据库表名的方法,通过游标和动态SQL实现自动化重命名,并添加统一前缀,适用于需要快速调整数据库结构的场景。

被折叠的 条评论
为什么被折叠?



