MySql

[Mysql] 테이블 제약사항 확인, 외래키 삭제, 추가, 제약 조건 무시

hwijin97 2021. 9. 8. 15:43

테이블 제약사항 조회

select * from information_schema.table_constraints
where TABLE_NAME = 'table_name';

 

테이블 생성 쿼리 확인후, 제약사항 확인

show create table `table`;

 

외래키 조건 삭제

alter table `table` drop foreign key `foreign_key_constraint_name`;

외래키 조건 추가

alter table `table` add foreign key(`foreign_key_col`) references `ref_table`(id);

외래키 제약 조건 무시

SET FOREIGN_KEY_CHECKS=0;
#query
SET FOREIGN_KEY_CHECKS=1;