1
Vote

Should use schema names when checking for constraints

description

It looks like foreign_keys was implemented correctly
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'----->[cf_team]<----,[FK_USER_TEAM_TAG_XREF_USER_TEAMS]') AND parent_object_id = OBJECT_ID(N'[cf_team].[USER_TEAM_TAG_XREF]'))
 
However when checking for defaults the scheme should also be included.
So:
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'---->?<----->[DF_USER_DEBITS_CREDITS_BALANCE]') AND type = 'D')
becomes
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'----->[cf_user]<----.[DF_USER_DEBITS_CREDITS_BALANCE]') AND type = 'D')
 
Without the schema it fails to find the default and will attempt to create this again.
 
Other than that it worked great on a fairly large schema!
 
Thanks for a great tool

comments