SQLD

[SQLD] INSERT 구문에 많이 나오는 문제(IDENTITY / CHECK)

여대마 2022. 10. 20. 13:12

INSERT 구문은 IDENTITY / CHECK 문제가 주로 나옴

 

IDENTITY(시작값,증가값)

(Sql Server)

-시작값 : 처음 행이 insert 될 때의 시작값

-증가값 : 다음 행이 insert 될 때 증가되는 값

해당컬럼에 특정값을 insert할 때 오류발생.

예) 

TBL_student

student_id Identity (1,1)

student_name NVARCHAR2(3)

 

INSERT INTO TBL_student VALUES(1,'김하나');

INSERT INTO TBL_student(student_name) VALUES('김두나');

 

결과)

1,김하나

2,김두나

 

CHECK(조건)

(Oracle)

-조건을 넣어서 해당 조건만 insert 됨

해당컬럼에 조건 이외의 값이 들어가면 오류

예)

TBL_student

student_higth CHECK(student_higth <180)

student_name NVARCHAR2(3)

 

INSERT INTO TBL_student VALUES(150,'김하나');

INSERT INTO TBL_student(student_name) VALUES(190,'김두나');

INSERT INTO TBL_student(student_name) VALUES(NULL,'김세나');

 

결과)

150,김하나

NULL,김세나(NULL값은 출력된다)