debugsqlMinor
Will SSDT publish always fail with "Data Loss May Occur" when table is rebuilt?
Viewed 0 times
publishlossmaywithoccuralwaysssdtfailwillwhen
Problem
Consider the following scenario:
My question is this: Can we rely on the fact that whenever the table needs to be rebuilt as part of a SSDT publish this error will be thrown?
- We have a SSDT database project.
- We add a new column to the middle of a table.
- This forces the database project to rebuild the table in order to deploy the change.
- We publish this SSDT database project with the setting “Block incremental deployment if data loss might occur” enabled.
- Because we have the above setting enabled, and (also, I think) the table is being rebuilt the deployment (correctly) throws an error saying data loss may occur.
My question is this: Can we rely on the fact that whenever the table needs to be rebuilt as part of a SSDT publish this error will be thrown?
Solution
Yes, you can rely on that. When you enable the "BlockOnDataLoss" attribute what actually happens is that SSDT adds to the deployment script a check like this one
IF EXISTS(SELECT 1 FROM TableToChange)
BEGIN
RAISEERROR ...
ENDCode Snippets
IF EXISTS(SELECT 1 FROM TableToChange)
BEGIN
RAISEERROR ...
ENDContext
StackExchange Database Administrators Q#91133, answer score: 3
Revisions (0)
No revisions yet.