公司的数据库规范SQL Server字段名称需要大写,最近检查数据库看到有些字段名称是小写。于是需要把小写的字段名称更改为大写,先找出下面的包含小写的SQL数据表。
SELECT c.name AS ColName, t.name AS TableName FROM sys.columns c JOIN sys.tables t ON c.object_id = t.object_id WHERE UPPER(c.[NAME]) COLLATE Latin1_General_CS_AS !=c.[NAME]
Google找到一篇文章,看到如何将表名或字段名更改为大写,地址是
How can I change the names of all tables to uppercase?
运行下面的SQL语句,可以将所有的字段名更改为大写。
SELECT ‘EXEC sp_rename ‘‘‘ + TABLE_SCHEMA + ‘.‘ + TABLE_NAME + ‘.‘ + COLUMN_NAME + ‘‘‘, ‘‘‘ + UPPER(COLUMN_NAME) + ‘‘‘,‘‘COLUMN‘‘‘ FROM INFORMATION_SCHEMA.COLUMNS WHERE OBJECTPROPERTY(OBJECT_ID(‘[‘ + TABLE_SCHEMA + ‘].[‘ + TABLE_NAME + ‘]‘), ‘isMSShipped‘) = 0
原文:http://www.cnblogs.com/JamesLi2015/p/4986253.html