Hi,
Firstly, a trigger is something that runs in the background as data is added, deleted or updated in a table. A trigger should never return any rows. This is just not permitted. I will assume that you are looking to create a stored procedure. There are several things that you should look closely at with this procedure:
- From a functional perspective, if the ID's are consecutive without any gaps then this will work. Have you considered looking for the MAX(ID) instead?
- There is no exception handling in the event that the query does not find a record.
I would propose something as follows:
Code:
CREATE PROCEDURE spUser()
BEGIN
DECLARE leer CHAR(16) DEFAULT 'True';
DECLARE ie INT;
DECLARE CONTINUE HANDLER
FOR NOT FOUND
SET leer = 'True';
SELECT id
INTO ie
FROM user
WHERE id = (SELECT Max(id)
FROM user);
IF ie > 0 THEN
SELECT *
FROM user;
ELSE
SELECT leer;
END IF;
END;