不可能知道在哪裏放大寫字母。當然有些猜測可能會有所幫助。但爲了確保,你需要檢查的數值手動
這個腳本會給你所有的字段和表駝峯:
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
哪個RDMS是這個? –
@ t-clausen.dk這是一個SQL Server系統 – Bas
您是否考慮過在部署在區分大小寫的整理服務器上時會發生什麼? –