Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SSDT script: Problem with order of 'DROP COLUMN' and 'DROP INDEX'

$
0
0

I am sorry! I posted this in the wrong forum. I reposted this question in the SSDT forum, but deleting this post seems to be impossible. Could a moderator delete this thread please?

Dear colleagues,

We use MS SQL Server 2012 and Visual Studio 2012 with database projects and hence the SSDT tools.

Did you ever encounter the problem sketched below, and if so, is there a way around it?

We have a table with a column that became obsolete. The column is indexed. Both index and column can be deleted. We deleted the objects in the database project. However, when we publish the project to a database, SSDT generates a script in which the column is dropped before the index. Naturally, you get an error that the column is still referenced by other objects. Dropping the index in the pre-script isn't the solution, since SSDT generates the publishing script before the pre-script is executed. So SSDT will still generate a drop statement for the index, generating an error that the index does not exist. Since our application is implemented at 600+ customers and different customers run different versions of our software, generating a script instead of publishing, and changing the order of the statements in the script is no possibility, since some of the customers might not even have a version that contains the table in question.

Below, I include a sample table. If you deploy this table to an empty database, import this in a database project in SQL Server, and then drop the column "indexed_column" and the index "dbo.SSDT_test.IDX_NU_SSDT_test#indexed_column" in the database project, you can reproduce the problem by publishing the database project to the database again.

Thank you for your help.

CREATE TABLE dbo.SSDT_test
  ( id               int   NOT NULL IDENTITY(1,1)
  , indexed_column   int   NOT NULL
  );
ALTER TABLE dbo.SSDT_test
  ADD CONSTRAINT PK_SSDT_test PRIMARY KEY (id);
CREATE INDEX IDX_NU_SSDT_test#indexed_column
  ON dbo.SSDT_test (indexed_column);

INSERT INTO dbo.SSDT_test (indexed_column)
SELECT 1 UNION ALL
SELECT 1 UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 5 UNION ALL
SELECT 8;

/*
-- Cleanup afterwards
DROP TABLE dbo.SSDT_test;
*/







Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>