简体   繁体   English

如何删除外键和主键

[英]How to delete foreign key as well as primary key

I want to use SQL and PHP to delete a specific row, events, and the foreign key eventlocation along with it. 我想使用SQL和PHP来删除特定的行,事件和外键事件位置。 I tried to use an inner join function, but this gave me an error. 我试图使用内部连接函数,但这给了我一个错误。 Any ideas? 有任何想法吗?

DELETE FROM Events, EventLocation JOIN ON EventLocation.EventLocationID = Events.EventLocationID WHERE EventID = '".$_POST["id"]."' AND EventLocationID = '".$_POST["id"]."'

使用内连接

DELETE Events, EventLocation FROM Events INNER JOIN EventLocation WHERE Events.EventID=EventLocation.EventID

Well bellow query works fine. 好贝娄查询工作正常。

DELETE Events, EventLocation FROM Events INNER JOIN EventLocation WHERE Events.EventID=EventLocation.EventID

But in this case you handle easily if the table EventLocation setting Cascade On Delete with EventID whwres EventID is a foreign key of table EventLocation and primary key of table Events . 但是在这种情况下,如果表EventLocation设置Cascade On Delete with EventID whwres EventID是表EventLocation的外键和表Events主键,则可以轻松处理。 Then you just delete row of Events . 然后你只需删除一行Events So the row of EventLocation delete autometically which along with Events . 所以EventLocation的行自动删除哪些以及Events

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM