SELECT * FROM information_schema.KEY_COLUMN_USAGE where table_name ='xxxx' and COLUMN_NAME = 'PPE_ID'
DROP PROCEDURE IF EXISTS SYS_UP;
CREATE PROCEDURE sys_up()
BEGIN
DECLARE ICOUNT INT DEFAULT 0;
IF ICOUNT = 0 THEN
SELECT COUNT(1)
INTO ICOUNT
FROM information_schema.KEY_COLUMN_USAGE where table_name ='xxxx' and COLUMN_NAME = 'PPE_ID'
AND T.TABLE_SCHEMA = DATABASE();
END IF;
IF ICOUNT = 0 THEN
alter table xxxx add constraint FK_xxxx3 foreign key (PPE_ID)
references yyyy (RID) on delete restrict on update restrict;
END IF;
END;
CALL SYS_UP();
网友评论