SlideServe
Menu
Preferences
ยฉ SlideServe ยท v2026

Master Intermediate SQL: Joins, Views, Integrity Constraints

twestfield avatar
39 slides ยท 423 Views ยท 390 likes ยท Jan 06, 2020

Learn how join operations work in SQL, including natural joins, outer joins, and joined relations. Explore views and their role in hiding data. Study examples and expand your skills with view creation and usage.

Master Intermediate SQL: Joins, Views, Integrity Constraints - slide 1
01 / 39Master Intermediate SQL: Joins, Views, Integrity Constraints
1 / 17

Download Presentation

Master Intermediate SQL: Joins, Views, Integrity Constraints
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

More Related Content

Presentation Transcript
  1. Chapter 4: Intermediate SQL

  2. Chapter 4: Intermediate SQL โ€ข ์กฐ์ธ ํ‘œํ˜„์‹ (Join Expressions) โ€ข ๋ทฐ (Views) โ€ข ๋ฌด๊ฒฐ์„ฑ (Integrity Constraints)

  3. ์กฐ์ธ ๋ฆด๋ ˆ์ด์…˜(Joined Relations) โ€ข ์ฃ ์ธ ์—ฐ์‚ฐ์€ ๋‘ ๋ฆด๋ ˆ์ด์…˜์„ ์ทจํ•ด ๋˜ ๋‹ค๋ฅธ ๋ฆด๋ ˆ์ด์…˜์„ ๊ฒฐ๊ณผ๋กœ ๋Œ๋ ค์ค€๋‹ค. โ€ข ์ฃ ์ธ ์—ฐ์‚ฐ์€ ์ฃผ์–ด์ง„ ์กฐ๊ฑด ํ•˜์— ๋‘ ๋ฆด๋ ˆ์ด์…˜๋‚ด์˜ ํŠœํ”Œ๋“ค์ด ๋งค์นญ๋˜๋Š” ๊ฒฐ๊ณผ๋งŒ์„ ํฌํ•จํ•˜๋Š” ์นดํ‹ฐ์…˜ ๊ณฑ ์—ฐ์‚ฐ์ด๋‹ค. ๋˜ํ•œ ์กฐ์ธ ๊ฒฐ๊ณผ์— ์–ด๋–ค ์• ํŠธ๋ฆฌ๋ทฐํŠธ๊ฐ€ ๋‚˜ํƒ€๋‚ ์ง€๋ฅผ ์ง€์ •ํ•œ๋‹ค. โ€ข ์ด๋“ค ๋ถ€๊ฐ€์ ์ธ ์—ฐ์‚ฐ์€ ์ผ๋ฐ˜์ ์œผ๋กœ from์ ˆ ๋‚ด์˜ ๋ถ€ ์งˆ์˜ ํ‘œํ˜„์‹์œผ๋กœ ์‚ฌ์šฉ๋œ๋‹ค. โ€ข select *from instructor natural join teaches;

  4. ์กฐ์ธ ์—ฐ์‚ฐ โ€“ Example โ€ข Relation course โ€ข Relation prereq โ€ข Observe that prereq informationis missing for CS-315 and courseinformationis missing for CS-347

  5. ์ž์—ฐ ์กฐ์ธ (Natural Join) โ€ข Natural join matches tuples with the same values for all common attributes, and retains only one copy of each common column โ€ข select *from instructor natural join teaches;

  6. Natural Join Example โ€ข List the names of instructors along with the course ID of the courses that they taught. โ€ข select name, course_idfrom instructor, teacheswhere instructor.ID = teaches.ID; โ€ข select name, course_idfrom instructor natural join teaches; โ€ข select name, course_idfrom instructor join teaches using(ID);

  7. Outer Join โ€ข ์ •๋ณด ์†์‹ค์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•œ ์กฐ์ธ ์—ฐ์‚ฐ์˜ ํ™•์žฅ. โ€ข ์กฐ์ธ์„ ๊ณ„์‚ฐํ•˜๊ณ  ๋‹ค๋ฅธ ๋ฆด๋ ˆ์ด์…˜์˜ ํŠœํ”Œ๊ณผ ๊ทธ ๊ฐ’์ด ์ผ์น˜ํ•˜์ง€ ์•Š๋Š” ์–ด๋–ค ๋ฆด๋ ˆ์ด์…˜์˜ ํŠœํ”Œ๋“ค์„ ์ฃ ์ธ์˜ ๊ฒฐ๊ณผ์— ์ถ”๊ฐ€ํ•œ๋‹ค. โ€ข ๋„ ๊ฐ’์„ ์‚ฌ์šฉํ•œ๋‹ค.

  8. Left Outer Join โ€ข coursenatural left outer joinprereq

  9. Right Outer Join โ€ข coursenatural right outer joinprereq

  10. Full Outer Join โ€ข coursenatural full outer joinprereq

  11. Joined Relations โ€ข ์กฐ์ธ ์—ฐ์‚ฐ์€ ๋‘ ๋ฆด๋ ˆ์ด์…˜์„ ์ทจํ•ด ๋˜ ๋‹ค๋ฅธ ๋ฆด๋ ˆ์ด์…˜์„ ๊ฒฐ๊ณผ๋กœ ๋Œ๋ ค์ค€๋‹ค. โ€ข ์ด๋“ค ๋ถ€๊ฐ€์ ์ธ ์—ฐ์‚ฐ์€ ์ผ๋ฐ˜์ ์œผ๋กœ from์ ˆ ๋‚ด์˜ ๋ถ€ ์งˆ์˜ ํ‘œํ˜„์‹์œผ๋กœ ์‚ฌ์šฉ๋œ๋‹ค. โ€ข ์กฐ์ธ ์กฐ๊ฑด (Join condition)- ๋‘ ๋ฆด๋ ˆ์ด์…˜๋‚ด์˜ ์–ด๋–ค ํŠœํ”Œ๋“ค์ด ๋ถ€ํ•ฉํ•˜๊ณ  ์กฐ์ธ ๊ฒฐ๊ณผ์— ์–ด๋–ค ์• ํŠธ๋ฆฌ๋ทฐํŠธ๊ฐ€ ๋‚˜ํƒ€๋‚ ์ง€๋ฅผ ์ •ํ•œ๋‹ค. โ€ข ์ฃ ์ธ ์œ ํ˜• (Join type)- ๋‹ค๋ฅธ ๋ฆด๋ ˆ์ด์…˜์˜ ์–ด๋–ค ํŠœํ”Œ๊ณผ ๋ถ€ํ•ฉํ•˜์ง€ ์•Š๋Š” ํŠœํ”Œ๋“ค์„ ์–ด๋–ป๊ฒŒ ์ทจ๊ธ‰ํ•  ๊ฒƒ์ธ๊ฐ€(์กฐ์ธ ์กฐ๊ฑด์— ๊ทผ๊ฑฐํ•ด)๋ฅผ ์ •ํ•œ๋‹ค.

  12. Joined Relations โ€“ Examples โ€ข select* from course (inner) join prereq oncourse.course_id = prereq.course_id โ€ข select * from course, prereqwhere course.course_id = prereq.course_id โ€ข What is the difference between the above, and a natural join? โ€ข course left outer join prereq oncourse.course_id = prereq.course_id

  13. Joined Relations โ€“ Examples โ€ข course natural right outer join prereq โ€ข coursefullouter join prereq using(course_id)

  14. ๋ทฐ(Views) โ€ข ์–ด๋–ค ๊ฒฝ์šฐ์—๋Š”, ์‹œ์Šคํ…œ์˜ ๋ชจ๋“  ์‚ฌ์šฉ์ž์—๊ฒŒ DB์˜ ์ „์ฒด์ ์ธ ๋…ผ๋ฆฌ์  ๋ชจ๋ธ์„ ๊ณต๊ฐœํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋žŒ์ž‘ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค. โ€ข ์–ด๋–ค ์‚ฌ๋žŒ์ด ๊ฐ•์‚ฌ์˜ ID, ์ด๋ฆ„, ํ•™๊ณผ๋ช…์„ ์•Œ๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ (๋‹จ ๊ธ‰์—ฌ๋Š” ํ•„์š” ์—†์Œ), ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์งˆ์˜๋ฅผ ์ž‘์„ฑํ•˜์—ฌ์•ผ ํ•œ๋‹ค. select ID, name, dept_namefrom instructor โ€ข ๋ทฐ (view)๋Š” ์–ด๋–ค ์‚ฌ์šฉ์ž์˜ ๋ทฐ๋กœ๋ถ€ํ„ฐ ์–ด๋–ค ๋ฐ์ดํ„ฐ๋ฅผ ์ˆจ๊ธฐ๋Š” ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค. โ€ข ๋ทฐ๋Š” DB์˜๊ฐœ๋… ๋ชจ๋ธ์— ํ•ด๋‹นํ•˜์ง€ ์•Š์œผ๋ฉฐ, ์˜ค์ง ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์ด๋Š” ๋ชฉ์ ์˜ ๊ฐ€์ƒ ๋ฆด๋ ˆ์ด์…˜ (virtual relation)์„ ์˜๋ฏธํ•œ๋‹ค.

  15. ๋ทฐ ์ •์˜ โ€ข ๋ทฐ๋ฅผ ์ƒ์„ฑํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์„ ์‚ฌ์šฉํ•œ๋‹ค. create view v as < query expression > ์—ฌ๊ธฐ์„œ: - <์งˆ์˜ ํ‘œํ˜„์‹>์€ ์ ๋ฒ•ํ•œ ํ‘œํ˜„์‹์ด๋‹ค. - ๋ทฐ๋ช…์€ v๋กœ ํ‘œํ˜„๋œ๋‹ค. โ€ข ์ผ๋‹จ ๋ทฐ๊ฐ€ ์ •์˜๋˜๋ฉด, ๋ทฐ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฐ€์ƒ ๋ฆด๋ ˆ์ด์…˜์„ ์ฐธ์กฐํ•˜๋Š”๋ฐ ๋ทฐ๋ช…์ด ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋‹ค. โ€ข ๋ทฐ ์ •์˜๋Š” ์งˆ์˜ ํ‘œํ˜„์‹์„ ํ‰๊ฐ€ํ•จ์œผ๋กœ์จ ์ƒˆ๋กœ์šด ๋ฆด๋ ˆ์ด์…˜์„ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ๊ณผ๋Š” ๋‹ค๋ฅด๋‹ค. ๋Œ€์‹ , ๋ทฐ ์ •์˜๋Š” ๋ทฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์งˆ์˜๋‚ด์— ๋Œ€์น˜๋  ํ‘œํ˜„์‹์„ ์ €์žฅํ•œ๋‹ค.

  16. Example Views โ€ข A view of instructors without their salarycreate view faculty asselect ID, name, dept_namefrom instructor โ€ข Find all instructors in the Biology departmentselect namefrom facultywhere dept_name = โ€˜Biologyโ€™ โ€ข Create a view of department salary totalscreate view departments_total_salary(dept_name, total_salary) as select dept_name, sum (salary)from instructorgroup by dept_name;

  17. ๋‹ค๋ฅธ ๋ทฐ ์ •์˜๋ฅผ ์ด์šฉํ•œ ์ƒˆ๋กœ์šด ๋ทฐ ์ •์˜ โ€ข create view physics_fall_2009as select course.course_id, sec_id, building, room_numberfrom course, sectionwhere course.course_id = section.course_idand course.dept_name = โ€™Physicsโ€™and section.semester = โ€™Fallโ€™and section.year = โ€™2009โ€™; โ€ข create view physics_fall_2009_watson as select course_id, room_numberfrom physics_fall_2009where building= โ€™Watsonโ€™;

  18. ๋ทฐ ํ™•์žฅ โ€ข Expand use of a view in a query/another view create view physics_fall_2009_watson as (select course_id, room_number from (select course.course_id, building, room_number from course, section where course.course_id = section.course_id and course.dept_name = โ€™Physicsโ€™ and section.semester = โ€™Fallโ€™ and section.year = โ€™2009โ€™) where building= โ€™Watsonโ€™;

  19. ๋‹ค๋ฅธ ๋ทฐ๋ฅผ ์‚ฌ์šฉํ•ด ์ •์˜ํ•œ ๋ทฐ โ€ข ํ•˜๋‚˜์˜ ๋ทฐ๋Š” ๋‹ค๋ฅธ ๋ทฐ๋ฅผ ์ •์˜ํ•˜๋Š” ํ‘œํ˜„์‹์— ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋‹ค. โ€ข ๋ทฐ ๋ฆด๋ ˆ์ด์…˜ v1์€ v2๊ฐ€ v1์„ ์ •์˜ํ•˜๊ณ  ์žˆ๋Š” ํ‘œํ˜„์‹์— ์‚ฌ์šฉ๋œ๋‹ค๋ฉด ๋ทฐ ๋ฆด๋ ˆ์ด์…˜ v2์— ์ง์ ‘ ์ข…์†ํ•œ๋‹ค๊ณ  ๋งํ•œ๋‹ค. โ€ข ๋ทฐ ๋ฆด๋ ˆ์ด์…˜ v1์€ ์ข…์† ๊ทธ๋ž˜ํ”„๋‚ด์— v2์—์„œ v1๋กœ์˜ ๊ฒฝ๋กœ๊ฐ€ ์กด์žฌํ•˜๋ฉด ๋ทฐ ๋ฆด๋ ˆ์ด์…˜ v2์— ์ข…์†ํ•œ๋‹ค๊ณ  ๋งํ•œ๋‹ค. โ€ข ๋ทฐ ๋ฆด๋ ˆ์ด์…˜ v๊ฐ€ ๊ทธ ์ž์‹ ์— ์ข…์†ํ•˜๋ฉด ์ˆœํ™˜์ ์ด๋ผ ๋งํ•œ๋‹ค.

  20. ๋ทฐ ํ™•์žฅ โ€ข ๋‹ค๋ฅธ ๋ทฐ์˜ ์šฉ์–ด๋กœ ์ •์˜๋œ ๋ทฐ์˜ ์˜๋ฏธ๋ฅผ ์ •์˜ํ•˜๋Š” ๋ฐฉ๋ฒ• โ€ข ๋ทฐ v1์„ ๊ทธ ์ž์‹ ์ด ๋ทฐ ๋ฆด๋ ˆ์ด์…˜์˜ ์‚ฌ์šฉ์„ ๋‚ดํฌํ•  ์ˆ˜ ์žˆ๋Š” ํ‘œํ˜„์‹ e1์œผ๋กœ ์ •์˜๋œ๋‹ค ํ•˜์ž. โ€ข ํ‘œํ˜„์‹์˜ ๋ทฐ ํ™•์žฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋Œ€์น˜ ์ ˆ์ฐจ๋ฅผ ๋ฐ˜๋ณตํ•œ๋‹ค. repeat e1์—์„œ ์–ด๋– ํ•œ ๋ทฐ ๋ฆด๋ ˆ์ด์…˜ vi๋ฅผ ์ฐพ๋Š”๋‹ค. ๋ทฐ ๋ฆด๋ ˆ์ด์…˜ vi๋ฅผ vi๋ฅผ ์ •์˜ํ•˜๊ณ  ์žˆ๋Š” ํ‘œํ˜„์‹์œผ๋กœ ๋Œ€์น˜ํ•œ๋‹ค. until๋” ์ด์ƒ์˜ ๋ทฐ ๋ฆด๋ ˆ์ด์…˜์ด e1๋‚ด์— ์กด์žฌํ•˜์ง€ ์•Š์Œ โ€ข ๋ทฐ ๋ฆด๋ ˆ์ด์…˜์ด ์ˆœํ™˜์ ์ด์ง€ ์•Š์€ ํ•œ ์ด ๋ฃจํ”„๋Š” ์ข…๋ฃŒํ•  ๊ฒƒ์ด๋‹ค.

  21. ๋ทฐ์˜ ๊ฐฑ์‹  โ€ข faculty ๋ทฐ์— ์ƒˆ๋กœ์šด ํŠœํ”Œ์„ ์‚ฝ์ž…ํ•˜์‹œ์˜ค. insert into faculty values (โ€™30765โ€™, โ€™Greenโ€™, โ€™Musicโ€™); ์ด ์‚ฝ์ž…๋ฌธ์€ instructor relation ์—๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŠœํ”Œ ์‚ฝ์ž…๋ฌธ์œผ๋กœ ํ‘œํ˜„๋˜์–ด์•ผ ํ•œ๋‹ค. (โ€™30765โ€™, โ€™Greenโ€™, โ€™Musicโ€™, null)

  22. Some Updates cannot be Translated Uniquely โ€ข create view instructor_info as select ID, name, buildingfrom instructor, departmentwhere instructor.dept_name= department.dept_name; โ€ข insert intoinstructor_info values (โ€™69987โ€™, โ€™Whiteโ€™, โ€™Taylorโ€™); โ€ข which department, if multiple departments in Taylor? โ€ข what if no department is in Taylor? โ€ข ๋Œ€๋ถ€๋ถ„์˜ SQL ์‹œ์Šคํ…œ์—์„œ๋Š” ์˜ค์ง ๋‹จ์ˆœํ•œ ๋ทฐ ๊ฐฑ์‹ ๋งŒ์„ ํ—ˆ์šฉํ•œ๋‹ค. ๋ณต์žกํ•œ ๋ทฐ์—์˜ ๊ฐฑ์‹ ์€ ๋ณ€ํ™˜ํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต๊ฑฐ๋‚˜ ๋ถˆ๊ฐ€๋Šฅํ•ด ํ—ˆ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.

  23. ๋ฌด๊ฒฐ์„ฑ ์ œ์•ฝ ์กฐ๊ฑด (Integrity Constraints) โ€ข ๋ฌด๊ฒฐ์„ฑ ์ œ์•ฝ ์กฐ๊ฑด์€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์˜ ๊ถŒํ•œ ์žˆ๋Š” ๋ณ€๊ฒฝ์ด ๋ฐ์ดํ„ฐ์˜ ์ผ๊ด€์„ฑ์„ ์žƒ์ง€ ์•Š๋„๋ก ๋ณด์žฅํ•จ์œผ๋กœ์จ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์šฐ๋ฐœ์ ์ธ ์†์ƒ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•œ๋‹ค. โ€ข A checking account must have a balance greater than $10,000.00 โ€ข A salary of a bank employee must be at least $4.00 an hour โ€ข A customer must have a (non-null) phone number

  24. ๋‹จ์ผ ๋ฆด๋ ˆ์ด์…˜์— ๋Œ€ํ•œ ๋ฌด๊ฒฐ์„ฑ ์ œ์•ฝ์กฐ๊ฑด โ€ข not null โ€ข primary key โ€ข unique โ€ข check (P), where P is a predicate

  25. Not Null ๊ณผ Unique ์ œ์•ฝ์กฐ๊ฑด โ€ข not null โ€ข Declare name and budget to be not null name varchar(20) not nullbudget numeric(12,2) not null โ€ข unique ( A1, A2, โ€ฆ, Am) โ€ข ์†์„ฑ A1, A2, โ€ฆ Am ์ด ํ›„๋ณดํ‚ค๋ฅผ ์ž„์„ ๋‚˜ํƒ€๋ƒ„.candidate key. โ€ข ํ›„๋ณดํ‚ค๋Š” null ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ (์ฃผํ‚ค์™€ ๋‹ค๋ฆ„).

  26. check ์ ˆ โ€ข check (P) ์—ฌ๊ธฐ์„œ P๋Š” ์ˆ ์–ด์ด๋‹ค. Example: semester ์†์„ฑ์€ โ€œfallโ€, โ€œwinterโ€, โ€œspringโ€ โ€œsummerโ€ ์ค‘ ํ•˜๋‚˜์˜ ๊ฐ’์„ ๊ฐ–๋Š”๋‹ค. create table section ( course_id varchar (8), sec_id varchar (8), semester varchar (6), year numeric (4,0), building varchar (15), room_number varchar (7), time slot id varchar (4), primary key (course_id, sec_id, semester, year), check(semester in (โ€™Fallโ€™, โ€™Winterโ€™, โ€™Springโ€™, โ€™Summerโ€™)));

  27. ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ(Referential Integrity) โ€ข ์ฃผ์–ด์ง„ ์• ํŠธ๋ฆฌ๋ทฐํŠธ์˜ ์ง‘ํ•ฉ์— ๋Œ€ํ•ด ํ•œ ๋ฆด๋ ˆ์ด์…˜์— ๋‚˜ํƒ€๋‚˜๋Š” ๊ฐ’์ด ๋‹ค๋ฅธ ๋ฆด๋ ˆ์ด์…˜์˜ ์–ด๋–ค ์• ํŠธ๋ฆฌ๋ทฐ์˜ ์ง‘ํ•ฉ์—๋„ ๋˜ํ•œ ๋‚˜ํƒ€๋‚˜๋„๋ก ํ•œ๋‹ค. โ€ข Example: ๋งŒ์•ฝ โ€œBiologyโ€ ๊ฐ€ instructor๋ฆด๋ ˆ์ด์…˜ ํŠœํ”Œ์— ๋‚˜ํƒ€๋‚˜๋Š” ํ•™๊ณผ๋ช… (department name)์ด๋ผ๋ฉด, department ๋ฆด๋ ˆ์ด์…˜์— โ€œBiologyโ€๋ฅผ ์œ„ํ•œ ํŠœํ”Œ์ด ์กด์žฌํ•˜์—ฌ์•ผ ํ•œ๋‹ค. โ€ข ํ˜•์‹์  ์ •์˜ - r1(R1)๊ณผ r2(R2)๋ฅผ ๊ฐ๊ฐ ์ฃผํ‚ค K1๊ณผ K2๋ฅผ ๊ฐ€์ง„ ๋ฆด๋ ˆ์ด์…˜์ด๋ผ ํ•˜์ž. - r2๋‚ด ๊ฐ๊ฐ์˜ t2์— ๋Œ€ํ•ด t1[K1] = t2[๏ก]์ธ r1๋‚ด์— ํŠœํ”Œ t1์ด ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค๋ฉด, R2์˜ ๋ถ€๋ถ„ ์ง‘ํ•ฉ ๏ก๋Š” ๋ฆด๋ ˆ์ด์…˜ r1์˜ K1์„ ์ฐธ์กฐํ•˜๋Š” ์™ธ๋ž˜ ํ‚ค์ด๋‹ค. - ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ ์ œ์•ฝ ์กฐ๊ฑด: ๏๏ก(r2) ๏ƒ ๏K1(r1)

  28. Cascading Actions in Referential Integrity โ€ข create table course ( course_id char(5) primary key,title varchar(20), dept_name varchar(20) references department) โ€ข create table course ( โ€ฆdept_name varchar(20),foreign key (dept_name) references departmenton delete cascade on update cascade, . . . ) โ€ข alternative actions to cascade: set null, set default

  29. Built-in Data Types in SQL โ€ข date: Dates, containing a (4 digit) year, month and date โ€ข Example: date โ€˜2005-7-27โ€™ โ€ข time: Time of day, in hours, minutes and seconds. โ€ข Example: time โ€˜09:00:30โ€™ time โ€˜09:00:30.75โ€™ โ€ข timestamp: date plus time of day โ€ข Example: timestamp โ€˜2005-7-27 09:00:30.75โ€™ โ€ข interval: period of time โ€ข Example: interval โ€˜1โ€™ day โ€ข Subtracting a date/time/timestamp value from another gives an interval value โ€ข Interval values can be added to date/time/timestamp values

  30. ์ธ๋ฑ์Šค ์ƒ์„ฑ โ€ข create table student (ID varchar (5),name varchar (20) not null,dept_name varchar (20),tot_cred numeric (3,0) default 0,primary key (ID)) โ€ข create index studentID_index on student(ID) โ€ข ์ธ๋ฑ์Šค๋Š” ๋ ˆ์ฝ”๋“œ ๊ฒ€์ƒ‰์„ ๊ณ ์†์œผ๋กœ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ์ƒ์„ฑํ•œ๋‹ค. โ€ข e.g. select * from studentwhere ID = โ€˜12345โ€™ can be executed by using the index to find the required record, without looking at all records of student More on indices in Chapter 11

  31. End of Chapter 4

  32. Figure 4.01

  33. Figure 4.02

  34. Figure 4.03

  35. Figure 4.04

  36. Figure 4.05

  37. Taylor Figure 4.07

  38. Figure 4.06

  39. Figure 4.03