简体   繁体   中英

Getting foreign key constraints from a MySQL table

I have a MySQL table with foreign key constraints, eg.

CREATE TABLE `yiingles_version` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `package_id` int(11) NOT NULL,
  `version` varchar(64) NOT NULL DEFAULT '',
  `distUrl` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `package_id` (`package_id`),

  CONSTRAINT `yiingles_version_ibfk_1` 
    FOREIGN KEY (`package_id`) REFERENCES `yiingles_package` (`id`) 
    ON DELETE CASCADE ON UPDATE CASCADE

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

How can I get programmatically the values for ON DELETE and ON UPDATE , in this case CASCADE ?

I've seen this question and also took a look at MySQL's information_schema database, but did not find a way to get the values mentioned above.

Have a look at the information_schema.referential_constraints table. Specifically, the UPDATE_RULE and DELETE_RULE columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM