Hello, I have two issues with the following code. 1) I don't think it is dropping all foreign keys which its suppose to from sysobjects.(The code runs without any errors) 2) the print function is not working. I would appreciate some guidance on finding out what my issue is. I'm sure its something simple. Thanks for taking a look.GOCREATE PROCEDURE uspDropUserForeignKeysASSET NOCOUNT ONDECLARE @strMessage VARCHAR(250) DECLARE @strForeignKey VARCHAR(250)DECLARE @strChildTable VARCHAR(250)DECLARE @strCommand VARCHAR(250)DECLARE @strTab CHAR = CHAR(9)---------------------Drop all user foreign keys------------------------PRINT @strTab + 'DROP ALL USER FOREIGN KEYS ...'DECLARE crsForeignKeys CURSOR FORSELECT name AS strForeignKey ,OBJECT_NAME(parent_obj) AS strChildTableFROM sysobjectsWHERE xtype='F' /* Foreign Keys Only */ AND ( name LIKE '%_FK' OR name LIKE '%_FK_' ) AND OBJECT_NAME(parent_obj) LIKE 'T%'ORDER BY nameOPEN crsForeignKeysFETCH NEXT FROM crsForeignKeys INTO @strForeignKey, @strChildTable-- Loop until no more recordsWHILE @@FETCH_STATUS = 0BEGIN SELECT @strMessage = @strTab + @strTab + '—DROP ' + @strForeignKey PRINT @strMessage-- Build command SELECT @strCommand = 'ALTER TABLE' + @strChildTable + 'DROP CONSTRAINT' + @strForeignKey-- Execute command EXECUTE(@strCommand) FETCH NEXT FROM crsForeignKeys INTO @strForeignKey, @strChildTableEND-- Clean upCLOSE crsForeignKeysDEALLOCATE crsForeignKeysPRINT @strTab + 'DONE'GO
Eric Lynch