将数据库所有表和字段首字母变成大写
时间:2021-07-01 10:21:17
帮助过:3人阅读
@tablename
varchar(
50)
declare @columnname
varchar(
50)
declare cur_table
cursor for select name
from sysobjects
where type=
‘U‘ open cur_table
fetch next from cur_table
into @tablename while @@fetch_status=
0 begin ----------------------------------------- declare cur_column
cursor for select name
from syscolumns
where id=Object_Id(@tablename)
open cur_column
fetch next from cur_column
into @columnname while @@fetch_status=
0 begin declare @ch
varchar(
50),@ch1
varchar(
50),@uppertablename
varchar(
50)
set @ch=@tablename+
‘.‘+@columnname
set @ch1=
upper(
substring(@columnname,
1,
1))+
substring(@columnname,
2,
len(@columnname)-
1)
set @uppertablename=
upper(
substring(@tablename,
1,
1))+
substring(@tablename,
2,
len(@tablename)-
1)
exec sp_rename @tablename,@uppertablename
exec sp_rename @ch,@ch1,
‘column‘ fetch next from cur_column
into @columnname
end close cur_column
deallocate cur_column
----------------------------------------- fetch next from cur_table
into @tablename
end close cur_table
deallocate cur_table
执行后整个数据库的表名和字段名都会变成首字母大写的形式。
将数据库所有表和字段首字母变成大写
标签: