doupu1957 2015-10-27 09:56
浏览 50
已采纳

PHP版本5.3.10删除外键

I am trying to drop a foreign key, and I know I have to drop its constraint before, but I keep geting this error:

#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'CONSTRAINT `fk_facility`' at line 2

First I did this :

ALTER TABLE `facilities` 
DROP CONSTRAINT `fk_facility`;

And I aimed to do this secondly:

ALTER TABLE `facilities` 
DROP FOREIGN KEY `building_Id`;

Show create table:

CREATE TABLE `facilities` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`building_Id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`type` varchar(255) DEFAULT NULL,
`area` varchar(255) DEFAULT NULL,
`capacity` varchar(255) DEFAULT NULL,
`quantity` tinyint(4) DEFAULT NULL,
`internet` char(13) DEFAULT NULL,
`availability` char(3) DEFAULT NULL,
`comments` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `fk_facility` (`building_Id`),
CONSTRAINT `fk_facility` FOREIGN KEY (`building_Id`) REFERENCES `buildings`
(`ID`) ON DELETE CASCADE) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=latin1
  • 写回答

1条回答 默认 最新

  • drk7700 2015-10-27 10:02
    关注

    To drop a FOREIGN KEY constraint, use the following SQL(MySQL is the odd one out):

    MySQL:

    ALTER TABLE facilities
    DROP FOREIGN KEY fk_facility
    

    SQL Server / Oracle / MS Access:

    ALTER TABLE facilities
    DROP CONSTRAINT fk_facility
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模数学建模需要
  • ¥15 c语言数据结构实验单链表的删除
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决