检查同一表中两列的条件

时间:2017-07-25 06:50:16

标签: mysql stored-procedures

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值

0 个答案:

没有答案