Michael Benjamin
Michael Benjamin

Reputation: 372264

How to change the column order of an Azure database table in Visual Studio

I've been searching all afternoon for the way to re-order columns of an Azure database table in MS Visual Studio 2022. No luck.

In other applications columns are easily re-arranged by dragging or cut & paste.

No can do here. At this point, I'm not even sure columns can be moved in VS.

I'm only interested in the VS output view. I'm not interested in altering the database.

More specifically, I need two columns, which are on opposite ends of the table to be moved next to each other for a QA task. If this can't be done, I would have to jump or scroll from one end of the row to the other (across multiple screen views). If I can compare the columns next to each other, the task will take hours. If I can't, it will take weeks.

I guess another option would be to temporarily hide all the columns in between. That would be a less preferable but acceptable solution, as well.

Any guidance would be appreciated. Thank you.

Upvotes: 4

Views: 1441

Answers (2)

LeoBulcsu
LeoBulcsu

Reputation: 11

If the table contains data, the easiest way to do this (in Azure Data Studio) would be to create the column by:

ALTER TABLE yourTable

ADD tableColumn dataType;

And then go to your table in your database, "design table", change the order and update.

This way the data would be kept in place and only the column would change its order.

This worked for me, at least. Hope this helps.

I don't know why there is not a simpler way to change the column order, but I guess it is because you can always SELECT the columns in the order needed.

Upvotes: 1

NickW
NickW

Reputation: 9818

If the table has no data in it then just replace it with one that has columns in the order you want.

If the table contains data then

  1. Create a new table with the columns in the order you want
  2. Copy the data from the old to new table
  3. Drop the old table, rename the new table

Or create a view over the existing table and query the view rather than the table

Upvotes: 2

Related Questions