ITeye博客

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

hipeace87 · 2009-03-04 16:29 · SQL · 数据库 · Markdown

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

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

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

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

评论(2)

  1. #2 楼 · hipeace87 · 2009-03-07 21:51

    不好意思,我还没用过这个 都是用MSSQL 。。。

  2. #1 楼 · for_cyan · 2009-03-06 16:47

    oracle怎么办,能不能通用

评论功能维护中,当前仅展示历史评论。