论坛首页 综合技术论坛

一次性更改数据库中所有用户表名称

浏览 2479 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-03-04   最后修改:2009-03-04

从网上下了一个系统,要想把数据库和项目中用到的整合到一起,不过会有重名发生

想把所有表都加上一个前缀,不过一个一个改又麻烦.就写了这个东西

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功能都很强大很有帮助

希望大家多交流。共同进步

   发表时间:2009-03-06  
oracle怎么办,能不能通用
0 请登录后投票
   发表时间:2009-03-07  
不好意思,我还没用过这个
都是用MSSQL  。。。
0 请登录后投票
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics