查询以更新HeidiSql中的表中的外键行

时间:2015-12-04 08:45:42

标签: mysql heidisql

在我的heidiSql数据库中,我有 ringee用户表 ..在该表中我有ringee用户ID,用户名,手机号,imei代码,是删除...这里 ringee用户ID是主键。我有另一个名为event table的表 ...这里我有事件ID,ringee用户ID,事件名称,地点......这里的事件id是Primary key和`ringee用户id是外键......

我需要的是,当该特定id的ringee用户ID发生变化时,我需要更新事件表中的ringee用户ID(外键)... 该怎么做。什么是查询...请帮我找...

这是我的事件表查询

CREATE TABLE `event` (
    `EVENT_ID` BIGINT(20) NOT NULL,
    `RINGEE_USER_ID` BIGINT(20) NOT NULL,
    `TEXT` VARCHAR(45) NOT NULL,
    `PLACE` VARCHAR(45) NOT NULL,
    `EVENT_DATE` DATETIME NOT NULL,
    `START_TIME` VARCHAR(10) NULL DEFAULT NULL,
    `END_TIME` VARCHAR(10) NULL DEFAULT NULL,
    `IS_DELETE` TINYINT(1) NULL DEFAULT '0',
    `CREATED_DTTM` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    `MODIFIED_DTTM` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`EVENT_ID`),
    INDEX `EVENT_ID` (`EVENT_ID`),
    INDEX `FK_EVENT_RINGEE_USER_ID` (`RINGEE_USER_ID`),
    CONSTRAINT `FK_EVENT_RINGEE_USER_ID` FOREIGN KEY (`RINGEE_USER_ID`) REFERENCES `ringee_user` (`RINGEE_USER_ID`) ON UPDATE NO ACTION ON DELETE NO ACTION
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

这里我需要更新ringee用户ID ..

1 个答案:

答案 0 :(得分:0)

尝试 CASCADE

(`RINGEE_USER_ID`) ON UPDATE CASCADE  ON DELETE NO ACTION

离。

CREATE TABLE GROUP(
     group_id INT NOT NULL,
     group_name VARCHAR(50),
     PRIMARY KEY (group_id)
) ENGINE=INNODB;

CREATE TABLE USER (
     user_id INT, 
     user_name VARCHAR(50), 
     group_id INT,
     FOREIGN KEY (group_id) REFERENCES GROUP (group_id) ON UPDATE CASCADE ON DELETE NO ACTION
) ENGINE=INNODB;