我可以在逻辑上重新排序表中的列吗? [英] Can I logically reorder columns in a table?

查看:33
本文介绍了我可以在逻辑上重新排序表中的列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我要向 Microsoft SQL Server 中的表添加一列,我能否控制该列在查询中的逻辑显示位置?

If I'm adding a column to a table in Microsoft SQL Server, can I control where the column is displayed logically in queries?

我不想弄乱磁盘上列的物理布局,但我希望尽可能在逻辑上将列组合在一起,以便 SQL Server Management Studio 等工具以方便的方式列出表的内容.

I don't want to mess with the physical layout of columns on disk, but I would like to logically group columns together when possible so that tools like SQL Server Management Studio list the contents of the table in a convenient way.

我知道我可以通过 SQL Management Studio 进入表的设计"模式并拖动列的顺序来完成此操作,但我希望能够在原始 SQL 中执行此操作,以便我可以执行从命令行编写的排序脚本.

I know that I can do this through SQL Management Studio by going into their "design" mode for tables and dragging the order of columns around, but I'd like to be able to do it in raw SQL so that I can perform the ordering scripted from the command line.

推荐答案

如果不创建新表,就无法以编程方式(以一种安全的方式)执行此操作.

You can not do this programatically (in a safe way that is) without creating a new table.

当您提交重新排序时,企业管理器所做的是创建一个新表,移动数据,然后删除旧表并将新表重命名为现有名称.

What Enterprise Manager does when you commit a reordering is to create a new table, move the data and then delete the old table and rename the new table to the existing name.

如果您希望您的列按特定顺序/分组而不改变它们的物理顺序,您可以创建一个可以随心所欲的视图.

If you want your columns in a particular order/grouping without altering their physical order, you can create a view which can be whatever you desire.

这篇关于我可以在逻辑上重新排序表中的列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆