1. 외래키 테이블 락 걸기
lock table 참조테이블명 write, 내테이블명 write; //foreign key가 걸려있는 내테이블과 참조테이블에 lock
lock table course write, attend write;
2. 외래키 지우기
alter table 내테이블명 drop foreign key 내테이블명_ibfk_2; //내테이블에서 참조데이블을 끊기!
alter table attend drop foreign key attend_ibfk_2;
3. 속성 넣기
alter table course modify co_num int not null auto_increment; //참조테이블의 속성 설정 다시하기
alter table 참조테이블명 modify 칼럼명 int not null auto_increment;
3. 외래키 설정
alter table 내테이블명 add foreign key(내칼럼명) referenses 참조테이블명(참조칼럼명); //외래키 재설정
alter table attend add foreign key(at_co_num) referenses course(co_num);
4. 락 해제
unlock tables;
'DB > 명령프롬프트 - mysql' 카테고리의 다른 글
[MySQL] 뷰 view 생성, 수정, 삭제 (1) | 2023.03.30 |
---|---|
[MySQL] 인덱스(색인) index 생성, 추가, 삭제 (0) | 2023.03.30 |
[MySQL] auto_increment 초기화방법 (0) | 2023.03.29 |
[MySQL] SQL 내장함수 : 정보함수 (0) | 2023.03.28 |
[MySQL] ERD 생성 (0) | 2023.03.28 |