deletion | delete from 테이블이름 : 모든 투플값들을 삭제한다. 테이블은 남아있음 //drop table 테이블이름 delete from 테이블이름 where 조건 delete from 테이블이름 where 컬럼이름 in ( SFW ) //중첩질의문 가능, 즉 참/거짓으로 판정될 수 있는 형태의 조건 Q) delete all tuples in the instructor relation for those instructors associating with a department located in the Watson Building => delete from instructor where dept_name in ( select dept_name from department where building = ‘Watson’) ; 바깥 질의의 dept_name은 테이블 이름 안 써도 됨. 위 테이블을 가리킨다! Q) delete all instructors whose salary is less than the average salary of instructors => delete from instructor where salary < ( select avg(salary) from instructor ); - outer쿼리의 삭제에 따라 instructor 테이블의 투플이 줄어들어서 서브쿼리 값이 계속 변함 -> 서브쿼리를 먼저 실행해서 그 값으로 그 위치를 대체 -> 그 뒤 서브쿼리를 다시 실행할 필요 없이, 해당되는 투플들을 다 삭제 |
'데이터베이스설계' 카테고리의 다른 글
[데이터베이스설계] 3-15 DB 변경연산 - update (0) | 2025.02.15 |
---|---|
[데이터베이스설계] 3-14 DB 변경연산 - insertion (0) | 2025.02.15 |
[데이터베이스설계] 3-12 Scalar 서브쿼리 (0) | 2025.02.15 |
[데이터베이스설계] 3-11 with 절 ( with 테이블명(컬럼명) as (투플 instance 정의) ) (0) | 2025.02.15 |
[데이터베이스설계] 3-10 from 절의 sub쿼리 (0) | 2025.02.15 |