sqlserver中将某数据库下的所有表字段名称为小写的改为大写

  1. declare @name varchar(50), @newname varchar(50),@colname varchar(50)  
  2. declare abc cursor for    
  3.   
  4. select (a.[name] + '.' + b.[name]) as tablename ,b.[name] colname  
  5.  from dbo.sysobjects a ,dbo.syscolumns b where a.id = b.id  
  6. and a.xtype= 'U'  
  7.   
  8. open abc    
  9. fetch next from abc into @name,@colname  
  10. while @@fetch_status=0 begin  
  11. set @newname=upper(@colname)  
  12. EXEC sp_rename @name,@newname,[COLUMN] print @colname PRINT @NEWNAME  
  13. fetch next from abc into @name,@colname  
  14. end  
  15. close abc  
  16. DEALLOCATE abc  

 

 

更改库中所有列名字段为小写

declare @sql varchar(300)
declare @tablecolumnname varchar(100), @columnname varchar(100)
declare cursor1 cursor for
select b.name+'.['+a.name+']',a.name from syscolumns a ,sysobjects b where a.id = object_id(b.name) and b.xtype = 'u' and a.xtype <>189 and a.xtype <>34 and a.xtype <>35 and a.xtype <>36
open cursor1
fetch next from cursor1 into @tablecolumnname,@columnname
while @@fetch_status=0
begin
set @sql='sp_rename '''+@tablecolumnname+''','''+LOWER(@columnname)+''',''column'''
--print @sql
exec(@sql)
fetch next from cursor1 into @tablecolumnname,@columnname
end
close cursor1
deallocate cursor1

posted @ 2015-12-30 12:29  无处安放的青春  阅读(1503)  评论(0编辑  收藏  举报