要求将数据库中所有的表名和列名全部改为大写,首先想到的就是在系统表中修改,数据库中的表名放在sysobjects表下,列名则放在syscolumns表下。
通常系统表是不可修改的,修改系统表之后出错,提示需要将allow update配置开关开启。写了下面的脚本
EXEC sp_configure 'allow update','1'
GO
UPDATE syscolumns SET syscolumns.name=upper(syscolumns.name)
WHERE syscolumns.name IN
(
SELECT syscolumns.name
FROM syscolumns,sysobjects
WHERE syscolumns.id=sysobjects.id
AND sysobjects.xtype='U'
)
GO
UPDATE sysobjects SET sysobjects.name=upper(sysobjects.name)
WHERE sysobjects.xtype='U'
GO
EXEC sp_configure 'allow update','0'
GO
结果还是出错,最后一查,发现配置allow update时要带上RECONFIGURE WITH OVERRIDE命令,SQL Server Books Online是这样描述的:
Updates the currently configured (the config_value column in the sp_configure result set) value of a configuration option changed with the sp_configure system stored procedure. Because some configuration options require a server stop and restart to update the currently running value, RECONFIGURE does not always update the currently running value (the run_value column in the sp_configure result set) for a changed configuration value.
原来如些阿,呵呵。