Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構

4.5. 外鍵(Foreign Key)

ON DELETE, ON UPDATE 事件觸發限制,可選參數: RESTRICT | CASCADE | SET NULL | NO ACTION

  1. RESTRICT(限制外表中的外鍵改動)

  2. CASCADE(跟隨外鍵改動)

  3. SET NULL(設空值)

  4. SET DEFAULT(設預設值)

  5. NO ACTION(無動作,預設的)

4.5.1. FOREIGN KEY (RESTRICT)

			
CREATE TABLE `bank_account_group_has_bank_account` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`bank_account_group_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	`bank_account_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	PRIMARY KEY (`id`),
	INDEX `FK_bank_account_group_has_bank_account_bank_account` (`bank_account_id`),
	INDEX `FK_bank_account_group_has_bank_account_bank_account_group` (`bank_account_group_id`),
	CONSTRAINT `FK_bank_account_group_has_bank_account_bank_account` FOREIGN KEY (`bank_account_id`) REFERENCES `bank_account` (`id`),
	CONSTRAINT `FK_bank_account_group_has_bank_account_bank_account_group` FOREIGN KEY (`bank_account_group_id`) REFERENCES `bank_account_group` (`id`)
)
COMMENT='bank_account_group 與 bank_account 的 N:M 關係'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=35;