CREATE PROCEDURE dup_uld
(IN DPD_ID int)
BEGIN
DECLARE CNT INT;
DECLARE MESSAGE_TEXT varchar(80);
SELECT COUNT(*) INTO CNT
FROM doctor_personal_details
WHERE ULD_ID = DPD_ID;
IF(CNT = 0 ) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'THIS ULD_ID ALREADY EXISTS';
END IF;
END;
列1:
DPD_ID
1
2
3
列2
ULD_ID
3
3
5
我的问题 ULD_ID不应重复每个DPD_ID值以指定一个ULD_ID值