简体   繁体   English

通过SSMS订购SQL Azure表列

[英]Order SQL Azure Table Columns via SSMS

I know you can go into the design view of a table in SQL Server Management Studios and reorder columns as they appear in the design view, however this isn't possible with SQL Azure as the option is disabled. 我知道您可以进入SQL Server Management Studios中的表的设计视图,并在设计视图中显示重新排序列,但是由于禁用了该选项,因此无法使用SQL Azure。 Is there a way to modify SQL Azure tables so that you can reorder their columns as they appear in the design view? 有没有办法修改SQL Azure表,以便您可以在设计视图中显示列重新排序?

I have been running a number of database upgrades over the last few months to support new requirements and would like to reorder the way the columns appear in design view so they're easier to read, ie so they start with a primary key, followed by foreign keys, then normal columns and end with the added by, modified by fields. 我在过去几个月里一直在运行许多数据库升级以支持新的需求,并希望重新排列列在设计视图中的显示方式,以便它们更容易阅读,即所以它们以主键开头,然后是外键,然后是普通列,最后添加,由字段修改。 Its purely to make the tables more readable as I manage them over time. 它纯粹是为了使表格更具可读性,因为我随着时间的推移管理它们。

Just run a script against the table. 只需针对表运行脚本。 Its a bit of pseudocode but you should get the idea. 它有点伪代码,但你应该明白这个想法。

CREATE TABLE TableWithDesiredOrder(PK,FK1,FK2,COL1,COL2)

INSERT INTO TableWithDesiredOrder(PK,FK1,FK2,COL1,COL2....)
SELECT PK,FK1,FK2,COL1,COL2.... FROM OriginalTable

DROP TABLE OriginalTable

Finally Rename the table 最后重命名表

sp_Rename TableWithDesiredOrder, OriginalTable

Just another option: I use SQL Delta to propagate my db changes from dev db up to Azure db. 另一种选择:我使用SQL Delta将我的db更改从dev db传播到Azure db。 So in this case, I just change the col order locally using SSMS GUI, and SQL Delta will do the createnew>copytonew>dropold for me, along with my other local changes. 所以在这种情况下,我只是使用SSMS GUI在本地更改col顺序,SQL Delta将为我执行createnew> copytonew> dropold,以及我的其他本地更改。 (In Project Options, I set Preserve Column Order=Yes.) (在“项目选项”中,我设置了“保留列顺序=是”。)

I experienced the same with Azure SQL Database, basically my view changes with ALTER were not taken when did a SELECT * from the view, or the column headers were mixed with the column values. 我在Azure SQL数据库中遇到了同样的问题,基本上我从视图中执行了SELECT *时没有采用ALTER进行视图更改,或者列标题与列值混合。

In order to fix it I dropped the view and re-created it again. 为了解决这个问题,我删除了视图并重新创建了它。 That worked. 那很有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM