Does sql pre and deploy runs in one session

Viewed 42

I have SQL VS project with one Customers.PreDeployment1.sql file:

DROP TABLE Customers

My question is, why after the deletion is happens, the Customers.sql (Build action) is not running (the table is not getting created in sql server)?

CREATE TABLE [dbo].[Customers]
(
    [Id] INT NOT NULL PRIMARY KEY, 
    [First_Name] NCHAR(10) NULL, 
    [Last_Name] NCHAR(10) NULL
)

I couldn't find any explanation for that... maybe because it consider it as one session?

1 Answers

Because the deletion doesn't happen until after visual studio has done its diff/compare and generated the script.

So the when the diff is performed (and the deploy script is created), the customers table is still in the DB, VS then adds pre-deploy and post deploy to the change script, then runs it.

I'm sure there's a good reason for this behaviour, but I've never found it. There are a few ways around the problem, but its not clear what you're trying to achieve by dropping the table in the predeploy?

Related