I realized that the behaviour of SQLPACKAGE.EXE changes depending on what changes have been made to a table schema:

  1. Adding a new column at the end of the table: "Table is changed"
  2. Removing a column from table: "Table is changed"
  3. Adding a column in between existing columns or just changing their order: "The recreation of the table was started"

(I did the translations myself, they maybe inaccurate but similar).

Step No. 3 takes forever during publishing process. I wonder why and what exactly is going on. I suspect the table structures are recreated entirely. I would not want this, I woul`d basically not care very much about the columns orders in the different target systems. Is there any way to prevent this time consuming process?

Edit:

Meanwhile I found that many people are struggeling with the same problem. SSDT does not have any option to ignore the column order of the target tables. That makes it re-arrenge all the data as described above. This is time consuming and entirely useless, but there is no choice if you want to use SSDT.

See & please upvote here:

Visual Studio Uservoice Item

Microsoft Connect Item

MSDN Forum Discussion

You are correct, the only way to "rearrange" the order of the columns is to create a table with the new structure and push the old data into it, drop the old table and then rename the new table (or some variation of that). It requires copying all the data in the table and some drops and renames.

Is there any way to prevent this time consuming process?

There sure is! Stop caring about column order. If it is that important, be willing to pay the price, or spend more time up front on the design so that you're not re-deploying the same table multiple times before you get the column order "right."

SSMS does the exact same thing if you use the table designer and change the order of columns - it will create a new table, copy all of the data, drop the old table, and rename the new one. This is not cheap - it takes time for the sheer physical data movement, and that movement has to be fully logged.

You'll notice, too, that there is no T-SQL / DDL command that allows you to specify the physical location of a new column; this is because SQL Server doesn't support it without rebuilding.

And it shouldn't really matter, anyway. Your application can be coded to ask for the columns in whatever order it wants, regardless of underlying physical implementation. If this is for the lazy SELECT * spot-checkers, create a view for them.

  • please let me point out that I absolutely do not care for the column order. The problem is that the different target servers have DIFFERENT column orders for unknown reason. Now when I come up with my new coded db solution and did first test deployments against those schemas, I see some of them behave that way. So it looks like I have to pay this price once :-( – Magier Feb 25 '16 at 11:22
  • EntityFrameworkCore does not respect column order and you may result in different schemas depending on the "history" of EF migrations :) – nsb Feb 3 '17 at 14:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.