4

What is the MySQL equivalent of RAISERROR in SQL Server?

CREATE procedure GetallFiles()
as
begin
if not exists(select files.Files,Users.FirstName,Users.LastName,Users.EmailAddress from files,Users
where files.UserID = Users.UserID)
raiserror('cannot find files records',16,1)
end
begin

select files.Files,Users.firstname,Users.lastname,Users.EmailAddress from files,Users
where files.UserID = Users.UserID
end
return
Nick
  • 7,103
  • 2
  • 21
  • 43
David Jones
  • 91
  • 2
  • 8
  • 1
    When you say SQL do you mean SQL Server? – Nick Aug 12 '16 at 18:12
  • 2
    Possible duplicate of [How to raise an error within a MySQL function](http://stackoverflow.com/questions/465727/how-to-raise-an-error-within-a-mysql-function) – Nick Aug 12 '16 at 18:16
  • yes sql server as in from sql server to mysql since I don't know what is the similar to raiserror of sql server for mysql since in mysql there is no such thing as raiserror('cannot find files records',16,1) – David Jones Aug 12 '16 at 18:40
  • Did you research at all? Look at the link in my above comment... – Nick Aug 12 '16 at 18:41

1 Answers1

4
    SET @s = 'Unknown condition type  !';
    SIGNAL SQLSTATE '45001' SET MESSAGE_TEXT = @s;
  • 1
    Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its long-term value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made. – Toby Speight Nov 17 '17 at 12:53