Problem with unnamed contraints
RexJolliff
Posts: 1 New member
We have problems when someone has creates a constraint in certain ways which causes the generation of a random name for the constraint (ie DF_Table_xx_A89FDC). ReadyRoll generates a DROP CONSTRAINT at the beginning of the script which fails at any site other than development (or at least any site where the constraint was created the same way). We replace the errant drop with code similar to the following to fix this:
Would it be possible to get ReadyRoll to generate code like this at least when it detects auto-generated constraint names? Also for primary keys it would be appreciated. (our template code looks different for primary keys)
IF EXISTS (SELECT o.name
FROM sys.objects o
JOIN sys.syscolumns c ON c.cdefault = o.object_id
WHERE o.parent_object_id = OBJECT_ID(N'Rooms')
AND o.type = 'D'
AND c.name = N'MediaDeliveryMethod')
BEGIN
DECLARE @command NVARCHAR(MAX)
SELECT @command = 'ALTER TABLE [dbo].[Rooms] DROP CONSTRAINT [' + o.name + ']'
FROM sys.objects o
JOIN sys.syscolumns c ON c.cdefault = o.object_id
WHERE o.parent_object_id = OBJECT_ID(N'Rooms')
AND o.type = 'D'
AND c.name = N'MediaDeliveryMethod';
EXECUTE (@command);
END;
GO
Would it be possible to get ReadyRoll to generate code like this at least when it detects auto-generated constraint names? Also for primary keys it would be appreciated. (our template code looks different for primary keys)
Tagged:
Answers
Thank you for your Forum Post.
My first thought on reading on your post, would be to simply set the Compare option to Ignore constraint Names and / or Ignore system named constraint names.
However, within Ready Roll, these options are by default turned off to ensure deployment reliability. See the Unsupported Options section in this help article:
https://documentation.red-gate.com/rr1/key-concepts/configuring-comparison-script-generation-options
Alternatively you can create your own Pre and Post Deployment scripts using your code template to handle auto-generated constraint names:
https://documentation.red-gate.com/rr1/key-concepts/include-scripts
Many Thanks
Eddie
Senior Product Support Engineer
Redgate Software Ltd
Email: support@red-gate.com
That being said, it would be nice for SCA to generate these according to some pattern and offer to fix your dev db
Any workaround to this problem.
Thanks
Gill