Order Azure SQL table columns through SSMS

I know that you can go into the table design view in SQL Server Management Studios and reorder the columns as they appear in the design view, however this is not possible in SQL Azure because the option is disabled. Is there a way to change Azure SQL tables so that you can reorder your columns as they appear in the design view?

Over the past few months, I have updated several database updates to support the new requirements and would like to change the order of the columns in the design view so that they are easier to read, i.e. they start with the primary key, followed by foreign keys, then regular columns and end with the addition changed by fields. Its purely to make tables more readable as I manage them over time.

+6
source share
2 answers

Just run the script for the table. This is a bit of pseudo code, but you should get this 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 
0
source

Another option: I use SQL Delta to propagate my db changes from dev db to Azure db. Thus, in this case, I just change the col order in local mode using the SSMS GUI, and SQL Delta will execute the createnew> copytonew> dropold command for me, as well as other local changes. (In the project settings, I set Preserve Column Order = Yes.)

0
source

Source: https://habr.com/ru/post/913427/


All Articles