不可能知道在哪里放置大写字母。当然,一些猜测会有所帮助。但为了确保,您需要手动检查值
该脚本将为您提供所有字段和表格的骆驼大小写:
select b.table_schema + '.'+a.table_name+'.'+column_name tablecolumn,
upper(left(column_name, 1))+ lower(stuff(column_name, 1,1,'')) newcolumn
into #t
from INFORMATION_SCHEMA.COLUMNS a
join
INFORMATION_SCHEMA.TABLES b
on a.table_name = b.table_name
and b.table_type = 'base table'
insert #t
select table_schema + '.' + table_name tablecolumn,
upper(left(table_name, 1))+ lower(stuff(table_name, 1,1,'')) newcolumn
from INFORMATION_SCHEMA.TABLES
在这里,您可以从 #t 中选择 * 并将值操作为您需要的任何值,然后再运行此脚本的最后一部分。
-- here is an example how you can replace columns like
-- SYSTEMNAME to SystemName, and EMPLOYEEID to EmployeeId in the temporary table
update #t set newcolumn = replace(replace(newcolumn, 'name', 'Name'), 'id', 'Id')
--loop cursor
Declare @tablecolumn as nvarchar(500)
Declare @newcolumn as nvarchar(500)
Declare SqlCursor CURSOR FAST_FORWARD FOR
SELECT tablecolumn, newcolumn FROM #t
OPEN SqlCursor
FETCH NEXT FROM SqlCursor
INTO @tablecolumn, @newcolumn
WHILE @@FETCH_STATUS = 0
BEGIN
-- This is the actual renaming
EXEC sp_rename @tablecolumn, @newcolumn
FETCH NEXT FROM SqlCursor
INTO @tablecolumn, @newcolumn
END
CLOSE SqlCursor
DEALLOCATE SqlCursor
drop table #t