Home > Back-end >  Delete Stored Procedure not working in SQL
Delete Stored Procedure not working in SQL

Time:10-26

I'm trying to create a stored procedure for deleting a record in my table.

I have tried the following but it doesn't seem to work:

Delimiter //
CREATE PROCEDURE BIRD_STRIKE_INCIDENT_DELETE  @row text
AS 
BEGIN
    DELETE FORM bird_strike.incidents WHERE row_names = @row
END
 delimiter ; 
 
 Call BIRD_STRIKE_INCIDENT_DELETE('11')

Can someone provide pointers on what I might be doing wrong here?

Thanks!

CodePudding user response:

Your code looks more like SQL Server than MySql

This should be so

Delimiter //
CREATE PROCEDURE BIRD_STRIKE_INCIDENT_DELETE  (_row text)
BEGIN
    DELETE FROM bird_strike.incidents WHERE row_names = _row;
END//
delimiter ; 

CodePudding user response:

You can consider this approach.

IF EXISTS(SELECT 1 FROM sys.procedures 
          WHERE Name = 'BIRD_STRIKE_INCIDENT_DELETE')
BEGIN
    DROP PROCEDURE dbo.BIRD_STRIKE_INCIDENT_DELETE;
END;
else
BEGIN
      CREATE PROCEDURE BIRD_STRIKE_INCIDENT_DELETE  (_row text)
      BEGIN
         DELETE FROM bird_strike.incidents WHERE row_names = _row;
      END
END;
  • Related