MySQL ON UPDATE / ON删除CASCADE而非CASCADing

时间:2011-11-17 01:01:02

标签: mysql relational-database innodb foreign-key-relationship

当我在注册表上编辑UID时,客户端表上的parentid列应该更改。它不是那样做的。有什么建议吗?

客户

CREATE TABLE `clients` (
    `id` INT(255) NOT NULL AUTO_INCREMENT,
    `fname` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `lname` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `email` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `phone` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `parentid` INT(255) NOT NULL,
    `hphone` VARCHAR(12) NOT NULL COLLATE 'latin1_bin',
    `postal` VARCHAR(10) NOT NULL COLLATE 'latin1_bin',
    `city` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `address` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `province` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `country` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `sms` INT(1) NOT NULL,
    `semail` INT(1) NOT NULL,
    `gender` VARCHAR(6) NOT NULL COLLATE 'latin1_bin',
    `bday` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `bmonth` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    PRIMARY KEY (`id`),
    INDEX `parentid` (`parentid`),
    CONSTRAINT `FK_clients_signup` FOREIGN KEY (`parentid`) REFERENCES `signup` (`UID`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='latin1_bin'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=31751

注册

CREATE TABLE `signup` (
    `UID` INT(255) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `hash` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `email` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `fname` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `lname` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `address` TEXT NOT NULL COLLATE 'latin1_bin',
    `city` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `province` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `zip` VARCHAR(30) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `country` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `company` TEXT NOT NULL COLLATE 'latin1_bin',
    `addtime` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `logintime` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `user_ip` VARCHAR(16) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `pwd` VARCHAR(60) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `credits` INT(255) NOT NULL,
    `plan` INT(255) NOT NULL DEFAULT '1',
    `reset` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `expires` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
    `afid` INT(255) NOT NULL,
    `industryid` INT(255) NOT NULL,
    PRIMARY KEY (`UID`),
    UNIQUE INDEX `email` (`email`),
    UNIQUE INDEX `username` (`username`),
    INDEX `industryid` (`industryid`),
    INDEX `afid` (`afid`),
    INDEX `plan` (`plan`),
    CONSTRAINT `FK_signup_affiliates` FOREIGN KEY (`afid`) REFERENCES `affiliates` (`afid`) ON UPDATE CASCADE ON DELETE CASCADE,
    CONSTRAINT `FK_signup_plans` FOREIGN KEY (`plan`) REFERENCES `plans` (`pid`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='latin1_bin'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=27

1 个答案:

答案 0 :(得分:0)

它可能没有改变,因为你不可能改变注册表上的UID,因为它是主键,并且是自动递增的