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
网友评论