create table 테이블 변수 값 (
컬럼명 타입 (크기),
컬럼명1 타입(크기)
constraint 제약조건 제약변수명 (제약을 지정할 컬럼)
)
select * from information_schema.table_constraints;
select * from information_schema.table_constraints where table_name = 'trainee2';
제약조건 오류
error code 1048 column 't_id' cannot be null
error code 1062 : duplicate entry '20' for key 'trainee2.nk_trainee2'
테이블을 삭제하면 제약조건도 삭제됨
alter table trainee2 drop constraint nk_trainee2;
alter table trainee2 drop primary key;
alter table trainee2 add constraint primary key(t_id);
alter table trainee2 add constraint unique un_new_trainee2(t_age);
alter table trainee2 add constraint unique (t_email);
create table e(
e1 int,
e2 varchar(10)
constraint primary key (e1)
);
create table f(
f1 int,
f2 varchar(20)
e1 int, - - 웬만하면 참조하는 변수와 같은 변수로 만들어준다.
constraint foreign key (e1) references e(e1)
);
1. 테이블 삭제하기
drop table e;(x) 먼저 참조하고 있는 f테이블 먼저 지워줘야 함.
drop table f; → drop table e;
2. 데이터 삭제 하기
constraint foreign key (e1) references e(e1) on delete cascade;
delete from e where e1=3;
constraint foreign key (e1) references e(e1) on delete set null;
delete from e where e1=3;
- e테이블의 데이터2라는 값을 데이터234로 수정
- update e set e2='데이터234' where e1=2;
- update 테이블 set 컬럼=변경할데이터 where pk컬럼=값;
- mapper에 데이터 넣을 때 mysql에서 구문을 써본 후 스프링에 쓰기!