insert
-- 1
insert into employee values (1, 'MESSI', '1987-02-01', 'M', 'DEV_BACK', 100000000, null);
-- 2
insert into employee values (2, 'JANE', '1996-05-05', 'F', 'DSGN', 90000000, null);
-- 3
insert into employee (name, birth_date, sex, position, id) values ('JENNY', '2000-10-12', 'F', 'DEV_BACK', 3);
-- 4
insert into employee values
(4, 'BROWN','1996-03-13','M','CEO',120000000, null),
(5, 'DINGYO','1990-11-05','M','CTO',120000000, null),
(6, 'JULIA','1986-12-11','F','CFO',120000000, null),
(7, 'MINA','1993-06-17','F','DSGN',80000000, null),
(8, 'JOHN','1999-10-22','M','DEV_FRONT',65000000, null),
(9, 'HENRY','1982-05-20','M','HR',820000000,null),
(10, 'NICOLE','1991-03-26','F','DEV_FRONT',90000000, null),
(11, 'SUZANNE','1993-03-23','F','PO',75000000, null),
(12, 'CURRY','1998-01-15','M','PLN',85000000, null),
(13, 'JISUNG','1989-07-07','M','PO',90000000, null),
(14, 'SAM','1992-08-04','M','DEV_INFRA',70000000, null)
- insert시 attribute 이름을 생략할 경우 반드시 attribute가 정의된 순서대로 모두 insert할 데이터를 셋팅해주어야 합니다.
- 세 번째 방법처럼 attribute 이름을 명시하고 쿼리문을 작성할 경우 순서를 변경해서 insert할 데이터를 셋팅할 수 있으며, insert 하고싶은 데이터만 셋팅할 수 있습니다.
- 네 번째 방법은 여러 튜플을 한 번에 추가할 수 있습니다.
sql constraint로 인한 에러가 발생되었을 때 디버깅 방법
show create table employee;
- sql constraint로 인한 에러가 발생되었을 때 에러 문구를 확인하고 위 sql문을 실행하여 constraint 이름이 어떻게 정의되었는지 비교하여 디버깅하면 어떤 constraint에 의한 에러인지 찾기가 수월합니다.
update
update employee set dept_id = 1003 where id = 1;
update employee set salary = salary + 10000000 where dept_id = 1003;
update employee, works_on
set salary = salary * 2
where employee.id = works_on.empl_id and works_on.proj_id = 2003;
- update 문은 반드시 where 절을 신경써서 작성해주어야 합니다.
delete
delete from employee where id = 8;
delete from works_on where empl_id = 5 and proj_id != 2001;
-- 모든 project를 삭제
delete from project;
- update 문과 같이 where 절을 꼭 신경써서 작성해야 됩니다.