mysql删除外键约束

1.通过数据库创建表的语句查看外键约束名

SHOW CREATE TABLE movie

-- 建表语句如下
CREATE TABLE `movie` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(255) DEFAULT NULL,
  `filename` VARCHAR(255) DEFAULT NULL,
  `videoname` VARCHAR(255) DEFAULT NULL,
  `categoryid` INT(11) DEFAULT NULL,
  `areaid` INT(11) DEFAULT NULL,
  `author` VARCHAR(255) DEFAULT NULL,
  `yeartime` VARCHAR(255) DEFAULT NULL,
  `playtime` VARCHAR(255) DEFAULT NULL,
  `content` TEXT,
  `cs` INT(11) DEFAULT NULL,
  `score` DECIMAL(10,2) DEFAULT NULL,
  `create_time` DATETIME DEFAULT NULL,
  `update_time` DATETIME DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_movie_category` (`categoryid`),
  KEY `fk_movie_area` (`areaid`),
  CONSTRAINT `fk_movie_area` FOREIGN KEY (`areaid`) REFERENCES `area` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_movie_category` FOREIGN KEY (`categoryid`) REFERENCES `category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=INNODB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8

2.解除外键约束

`fk_movie_category`
`fk_movie_area`

ALTER TABLE movie DROP FOREIGN KEY `fk_movie_category`
ALTER TABLE movie DROP FOREIGN KEY `fk_movie_area`

至此,外键约束就解除,可以进行删除外键等操作。

你可能感兴趣的:(数据库,mysql,数据库,sql)