美文网首页
mysql 判断表外键

mysql 判断表外键

作者: 境与界 | 来源:发表于2020-08-20 14:23 被阅读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();

相关文章

网友评论

      本文标题:mysql 判断表外键

      本文链接:https://www.haomeiwen.com/subject/whwsjktx.html