mysql 判断表外键

2020-08-20  本文已影响0人  境与界
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();
上一篇下一篇

猜你喜欢

热点阅读