sqlserver中将某数据库下的所有表字段名称为小写的改为大写
- declare @name varchar(50), @newname varchar(50),@colname varchar(50)
- declare abc cursor for
- select (a.[name] + '.' + b.[name]) as tablename ,b.[name] colname
- from dbo.sysobjects a ,dbo.syscolumns b where a.id = b.id
- and a.xtype= 'U'
- open abc
- fetch next from abc into @name,@colname
- while @@fetch_status=0 begin
- set @newname=upper(@colname)
- EXEC sp_rename @name,@newname,[COLUMN] print @colname PRINT @NEWNAME
- fetch next from abc into @name,@colname
- end
- close abc
- 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