如何将 MS SQL Server 一个数据库中的所有表的所有列名更改为大写?
是否有任何sql语句用于将数据库中所有表的所有列名更改为大写?微软 SQL 服务器。
我有一个sql来做到这一点,但不确定它是否正确。
运行下面的SQL
select 'exec sp_rename '''+b.name+'.'+a.name+''','''+UPPER(a.name)+''',''列''' 来自 syscolumns a、sysobjects b 其中 a.id=b.id 和 b.type='U' 按 b.name 排序
复制并执行上面的结果
is there any sql statement used to change all column name to UPPER CASE for all tables in database? MS SQL Server.
I got a sql to do that, but not sure whether it`s correct.
run SQL below
select 'exec sp_rename '''+b.name+'.'+a.name+''','''+UPPER(a.name)+''',''column''' from syscolumns a, sysobjects b where a.id=b.id and b.type='U' order by b.name
copy and execute the result above
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您要将应用程序从 SQL Server 2000 升级到更高版本,并且您在 SQL Server 区分大小写方面遇到困难,我建议您在对 SQL Server 2000 进行重大更改之前先查看一下 SQL Server 2000 兼容性设置数据库。
在 SQL Server 2008 Management Studio 中,
properties
Options
页面。选择兼容性级别:SQL Server 2000
至少这很耗时。
编辑:由于 OP 似乎正在将其数据库从 SQL Server 2005 升级到 SQL Server 2005 上的“新”数据库,因此上述策略可能不是最佳的。
If you are upgrading an application from SQL Server 2000 to a later edition, and you are struggeling with SQL Server case sensitivity, I would suggest you look into the SQL Server 2000 compatibility setting before you do drastic changes to the database.
In SQL Server 2008 Management Studio
properties
in the context menuOptions
pageCompatibility Level: SQL Server 2000
At least that is time consuming.
Edit: Since it appears that OP is upgrading his database from SQL Server 2005 to a "new" database on SQL Server 2005, the above strategy might not be optimal.
我不相信有一个命令可以做到这一点。
但是,您应该能够编写一个查询来执行此操作,使用 1 或 2 个游标和如下查询:
这应该返回数据库中的所有表和列。
然后使用:
重命名每列。
I don't believe there is one command to do this.
However you should be able to write a query which does this, using 1 or 2 cursors and a query like:
This should return all table and columns in your database.
Then use:
To rename each column.
简短的回答 - 不。
如果您需要这样做(许多研究表明所有大写名称都会降低可读性),您必须使用这些大写名称生成新表,将数据从旧表复制到新表,删除旧表,重命名新表,并重新建立所有外键关系。
这样做有充分的理由吗?
Short answer - no.
If you need to do this (and many studies suggest that all upper case names detract from readability), you'll have to generate new tables with these upper case names, copy the data from the old to the new table, drop the old tables, rename the new tables, and re-establish all of the foreign key relationships.
Is there a good reason to do this?
扩展 Bravax 答案,这将为您提供要执行的命令列表,
如果您批量运行,您可能需要在行之间添加“go”
Extending Bravax answer, This will give you a list of commands to execute
You might need to add 'go' in-between lines if you are running as a bulk