MySQL ON DELETE CASCADE不起作用

时间:2017-08-29 07:32:14

标签: mysql mariadb

我有两个表(类型innoDb)为什么当我删除主表行像

+ note(我使用arch os,所以我的数据库服务器类型是maria db)

public string GetConnectionID()
{
     return "Your Connection ID as String"  //This can be stored in a list or retrieved in any other method
}

关系表行不要删除???

connectedUserID

1 个答案:

答案 0 :(得分:-1)

这个语法适用于MySQL数据库,但我也无法查看查询中的问题

CREATE TABLE  `rooms` (
  room_no INT PRIMARY KEY AUTO_INCREMENT,
  room_name VARCHAR(255) NOT NULL,
  building_no INT NOT NULL,
  CONSTRAINT `FK_rooms_1` FOREIGN KEY (`building_no`) REFERENCES `buildings` 
  (`building_no`) ON DELETE CASCADE
) ENGINE=InnoDB;

或在创建表格后添加约束

ALTER TABLE `rooms`
  ADD CONSTRAINT `FK_rooms_1` FOREIGN KEY (`building_no`) REFERENCES `buildings` (`building_no`) ON DELETE CASCADE ON UPDATE CASCADE;