Rerunnable scripts dropping functions in incorrect order
pblack
Posts: 2 New member
in SQL Compare
I am trying to create a re-runnable deployment script that requires modifying function1 (fnMain) and dropping function2 (fnSub) that calls function1 (fnMain).
This dependency is not being picked up and the resultant script fails as it is trying to drop function 1 before function2. Currently using version 14.0.7.13517 of SQL compare against SQL server 2014.
The script below is a simple test to reproduce the issue.
This dependency is not being picked up and the resultant script fails as it is trying to drop function 1 before function2. Currently using version 14.0.7.13517 of SQL compare against SQL server 2014.
The script below is a simple test to reproduce the issue.
USE master IF EXISTS( SELECT * FROM sys.databases AS d WHERE d.name = 'Test1') DROP DATABASE Test1; GO IF EXISTS( SELECT * FROM sys.databases AS d WHERE d.name = 'Test2') DROP DATABASE Test2; GO CREATE DATABASE Test1 GO USE Test1 GO CREATE FUNCTION [dbo].[fnMain]() RETURNS VARCHAR(MAX) WITH SCHEMABINDING AS BEGIN DECLARE @ret VARCHAR(MAX); RETURN @ret; END GO CREATE DATABASE Test2 GO USE Test2 GO CREATE FUNCTION [dbo].[fnMain]() RETURNS VARCHAR(MAX) WITH SCHEMABINDING AS BEGIN DECLARE @ret VARCHAR(MAX) = ''; RETURN @ret; END GO CREATE FUNCTION [dbo].[fnSub]() RETURNS VARCHAR(MAX) WITH SCHEMABINDING AS BEGIN RETURN dbo.fnMain(); END GO USE master GO<br>Use SQL compare to deploy from Test1 to Test2 (with the Add DROP and CREATE for rerunnable scripts checked) and the script will fail with the error cannot drop function dbo.fnMain because it is being referenced by object fnSub
Comments