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] ERD 대학수강프로그램 - 4. 테이블 업데이트 (update, case, if, modify) (0) | 2023.03.30 |
---|---|
[MySQL] ERD 대학수강프로그램 3. table이용 예시 (join) (0) | 2023.03.29 |
[MySQL] auto_increment 초기화방법 (0) | 2023.03.29 |
[MySQL] ERD 대학수강프로그램 2. 정보넣기 (0) | 2023.03.29 |
[MySQL] ERD 대학수강프로그램 1. 생성 (0) | 2023.03.29 |