2017-02-09 99 views

回答

0

用它来找到你的约束的名字:

select 
    table_name, 
    column_name, 
    constraint_name, 
    referenced_table_name, 
    referenced_column_name 
from information_schema.key_column_usage 
where table_name = 'Your_table'; 

,然后使用下面的语句删除它:

alter table your_table drop foreign key <foreign_key_constraint_name>; 
+0

是不是'SHOW CREATE TABLE tablename'足以看出外键名称? –

+0

几乎总是有多种方法可以做山姆的事情。我只是挑了其中一个。另外我更喜欢一个实际的查询。 – GurV

0
SELECT 
constraint_name 
FROM 
information_schema.REFERENTIAL_CONSTRAINTS 
WHERE 
constraint_schema = 'Blog' AND table_name = 'posts'; 


ALTER TABLE posts DROP Foreign Key keyname;