sql change control issue
The drop constraint is outside the if but the add is inside. This is a mistake. Please offer some guidance
-- <Migration ID="0d0c3512-b3c0-46dc-b40d-25f450a2aaa3" />
GO
SET IMPLICIT_TRANSACTIONS, NUMERIC_ROUNDABORT OFF;
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, NOCOUNT, QUOTED_IDENTIFIER ON;
SET DATEFORMAT YMD;
GO
PRINT (N'Drop constraint FK_TxMasterLoanOrNote_StpApplicationSnapshot from [dbo].[TxMasterLoanOrNote]');
ALTER TABLE [dbo].[TxMasterLoanOrNote] DROP CONSTRAINT [FK_TxMasterLoanOrNote_StpApplicationSnapshot];
GO
IF (SELECT COUNT(*)
FROM [dbo].[StpApplicationSnapshot]) = 0
BEGIN
PRINT (N'Add 2 rows to [dbo].[StpApplicationSnapshot]');
INSERT INTO [dbo].[StpApplicationSnapshot] ([ApplicationSnapshotID], [ApplicationSnapshotDesc])
VALUES (1, 'Origination');
INSERT INTO [dbo].[StpApplicationSnapshot] ([ApplicationSnapshotID], [ApplicationSnapshotDesc])
VALUES (2, 'ODS');
ALTER TABLE [dbo].[TxMasterLoanOrNote]
ADD CONSTRAINT [FK_TxMasterLoanOrNote_StpApplicationSnapshot] FOREIGN KEY ([ApplicationSnapshotID]) REFERENCES [dbo].[StpApplicationSnapshot] ([ApplicationSnapshotID]);
END
GO
Answers
Kind regards
Dan Calver | Redgate Software
Have you visited our Help Center?