1 / 42

데이터베이스

데이터베이스. 2003. 10. 8. 최진욱 jinchoi@snu.ac.kr. 강의내용. Database System vs File System Data Models Database Management System Structure. 데이터베이스의 정의. 데이터베이스란 (database) 데이터의 집합 특수한 목적을 위하여 설계되고 모아진 데이터. 데이터베이스 관리시스템. 데이터베이스 관리시스템이란 Database management system (DBMS)

Télécharger la présentation

데이터베이스

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

Presentation Transcript


  1. 데이터베이스 2003. 10. 8. 최진욱 jinchoi@snu.ac.kr

  2. 강의내용 • Database System vs File System • Data Models • Database Management System Structure

  3. 데이터베이스의 정의 • 데이터베이스란 (database) • 데이터의 집합 • 특수한 목적을 위하여 설계되고 모아진 데이터

  4. 데이터베이스 관리시스템 • 데이터베이스 관리시스템이란 • Database management system (DBMS) • 데이터베이스를 관리하는데 필요한 기능을 제공하는 S/W

  5. 데이터베이스 시스템의 발전 • 1960년대에 최초 데이터베이스 시스템 상품화 • File system에서 데이터베이스 시스템으로 발전

  6. File System에서의 Data관리 초등학교: 정제헌, 친구, 목동 장재영, 친구, 반포 김창기, 국어선생님, 고척동 …… 중학교: 장재영, 친구, 반포 윤상의, 친구, 수원 이가영, 친구, 봉천동 고등학교 장재영, 친구, 반포 장재영 초등학교 때부터 친구 반포, 고등학교 ….. People.hwp 친구 정제헌, 장재영, 윤상의 …. 선생님 김창기, 현수엽, 이미영 School.hwp Relation.hwp

  7. DBMS의 필수 기능 • 사용자가 데이터베이스를 디자인할 수 있어야 한다. • Data definition 기능 • 모든 사용자가 데이터를 조작할 수 있어야 한다. • Data manipulation 기능 • 대량의 데이터를 안전하게 저장할 수 있어야 한다. • Data and history protection • 많은 사람이 동시에 데이터를 볼 수 있어야 한다. • Database Accessibility 보장

  8. File System의 제약 • 사용자가 데이터베이스를 디자인 할 수 있어야 한다. • ‘나이칸에는 꼭 숫자만 들어가도록’ • 모든 사용자가 데이터를 조작할 수 있어야 한다. • ‘친구 중 동작구에 사는 사람은?’ • 대량의 데이터를 안전하게 저장할 수 있어야 한다. • 많은 사람이 동시에 데이터를 볼 수 있어야 한다.

  9. Drawbacks of File Systems (1) • In the early days, database applications were built on top of file systems • Drawbacks of using file systems to store data: • Data redundancy and inconsistency • Multiple file formats, duplication of information in different files • Difficulty in accessing data • Need to write a new program to carry out each new task • Data isolation — multiple files and formats • Integrity problems • Integrity constraints (e.g. account balance > 0) become part of program code • Hard to add new constraints or change existing ones

  10. Drawbacks of File Systems (2) • Drawbacks of using file systems (cont.) • Failure of Atomicity • Failures may leave database in an inconsistent state with partial updates carried out • 50,000 transfer from a bank account • Troubles in concurrent access by multiple users • Uncontrolled concurrent accesses can lead to inconsistencies • E.g. two people reading a balance and updating it at the same time • Security problems • Database systems offer solutions to all the above problems

  11. DBMS is now essential component Prudential Insurance Co. 1900s

  12. Modeling of Database

  13. View of Data An architecture for a database system

  14. Data Models • A collection of tools for describing • data • data relationships • data semantics • data constraints • Entity-Relationship model • Relational model • Other models: • object-oriented model • semi-structured data models • older models: network model and hierarchical model

  15. Entity-Relationship Model • 개념적 데이터 모델링 • 개체(entity) 와 개체 사이의 관계를 diagram으로 표현 • E-R Diagram의 기본요소 • Relational Model로 쉽게 연결됨 개체(entity) 관계 (relationship) 속성 (attribute)

  16. Entity-Relationship Model 환자_이름 환자-주소 의사_이름 환자-우편번호 환자_ ID 의사_ID 소속과 외래진료 환자 의사

  17. Entity-Relationship Model 장소 이름 시간 학점 년도 년도 학생 수강 개설 강좌 교수 강좌 강좌 요일 교수 횟수 학생 성적 지도 교수 학생 학번 학과 학년 직급 이름 학과 이름 직책

  18. Entity-Relationship diagram . PATIENT . . HAS Pt. ID TREATS name birth date . PHYSICIAN . ACCOUNT READS . X-RAY . . ORDERS . CONSISTS OF CONTAINS EXAM CHARGE . MAKES . USES . HAS EQUIPMENT COST PROFESSIONAL

  19. Relational model 구성요소 • Table • 현실에 존재하는 개체(정보)들을 관계적으로 표현한 형태 • 관계 또한 table로 표현 • Instance • table에 담겨져 있는 어느 개체를 나타내는 값 • tuple, record • Attribute • 개체를 설명하는 요소 Attribute (속성) 환자예약 테이블

  20. The examples Relation account relation customer relation deposit relation

  21. 환자질병 history table 김기영 조진호 김상덕 이기석 이준호 pneumonia URI AMI hepatitis alcoholic hepatitis Tables을 이용한 relation 표현 • 환자는 질병을 가진다. • 환자는 의사를 만난다. 환자 table 질병 table 김기영 조진호 김상덕 이기석 이준호 pneumonia gastritis URI AMI hepatitis alcoholic hepatitis . . . lipoma

  22. 외래진료 예약 table 김기영 김기영 김기영 조진호 김상덕 이기석 이준호 Dr. A Dr. B Dr. C Dr. D Dr. E Dr. F Dr. Z Table을 이용한 relation의 표현 • 환자는 질병을 가진다. • 환자는 의사를 만난다. 의사 table 환자 table 김기영 조진호 김상덕 이기석 이준호 Dr. A Dr. B Dr. C Dr. D Dr. E Dr. F . . . Dr. Z

  23. 환자진료 데이터베이스의 설계 • 기본키 (primary key) • 데이터를 구분하는 가장 근본이 되는 값 • Not null 이어야 하며 • Unique 하여야 한다.

  24. 데이터베이스의 디자인 • 외래키 (foreign key), 외부키 • 다른 테이블에서 정의된 값을 참조하여 사용할 때 외래키라 함

  25. 외래키의 조건 • 외래키가 될 수 있는 값들은 unique하여야 한다. • dangling 현상이 없어야 한다. • 존재하지 않는 값을 참조할 때 dangling 발생 • referential integrity (참조 무결성)

  26. 데이터베이스 설계-제약조건의 설계- • 개체무결성 (entity integrity) • 기본키는 각 레코드의 기본이 되는 값이므로 null 값을 가질 수 없다. • 참조무결성(referential integrity) • 외래키는 참조하는 테이블에 존재하는 값이어야 한다. • 도메인무결성 (domain integrity) • 데이터의 값은 해당 컬럼에서 존재할 수 있는 값을 지녀야 한다. (나이: 1000, 체중: 1000) • 사용자정의 무결성(general integrity) • 영화의 최고 등급을  로 정하고자 할 때

  27. 나쁜 설계의 예 1

  28. 나쁜 설계의 예 1 • 장점: • 학생별 지도교수 표시 불필요 • 단점: • 표(table)가 커진다. • 지도학생수에 대한 제한이 있다. • 5명 이상인 경우 구조변경 필요 • 4 명 이하인 경우 저장공간 낭비 • 변경이 어렵다: 중간에 삽입, 이동 곤란 • 정보의 검색이 어렵다: 노원구에 사는 학생?

  29. 나쁜 설계의 예 2

  30. 나쁜 설계의 예 2 • 장점: • 별도의 교수table 불필요 • 단점: • 데이터의 중복 기록: 디스크 저장장소 낭비 • 한 교수가 지도학생이 1 명 있는 경우: • 학생삭제  교수 삭제 • 학생 없는 교수 설정 불가능

  31. 데이터베이스 설계-테이블의 설계- • 각 테이블은 최소한의 의미만 갖도록 한다. • 한 개의 테이블은 하나의 주제만 갖도록 한다. • 테이블의 필드를 가능한 제한한다. • 다른 type의 데이터는 별도의 table로 만든다. • 성적 table, 기초정보 table, 소속과 table

  32. 각 개체를 잘 표현하고 있는 설계 학생 table 교수 table 학생지도 table

  33. DBMS Structure

  34. DBMS의 전체구조 Schema Modifications Queries Modifications Query Processor Transaction Manager Storage Manager Data Metadata

  35. Overview of DBMS component • Metadata • 데이터베이스를 이루고 있는 데이터에 대한 정보 • 속성, 제약조건, 사용자권한 • 각 필드에 사용되는 값 • Index • a data structure that helps us find data item quickly • Storage manager • Metadata, index등을 이용하여 자료의 안전한 저장, 효율적인 관리 등을 담당하는 모듈

  36. 주민번호 1012 3456 7890 5600 1000 이름 박문수 나연묵 이찬영 정기태 홍길동 Overview of DBMS component • Query Processor • 질의를 받아서 데이터를 찾는 기능을 수행 • 데이터를 찾는 질의에 대해서 가장 빠르게 답할 수 있도록 기능 최적화 주민번호 1000번인 고객의 잔액은 ? 고객 table 예금 table 고객계좌 table 계좌 0001 0002 0003 0004 0005 ... 잔액 1200 890 3000 4500 500 주민번호 3456 7890 1000 5600 1012 계좌 0001 0002 0003 0004 0005 ...

  37. Index file 인덱스파일 데이터 파일 키값 K1 K2 K3 • • • 레코드주소 • • • • • • Index를 사용하면 찾고자 하는 영역을 줄일 수 있다.

  38. 132 16 145 7 15 18 20 30 36 42 50 58 62 65 70 110 120 130 136 140 How Indexes are Implemented • B- tree index • generalization of a balanced binary search tree • each node occupies a full disk block 69 128 138 43 19 60 100 26 40 차수 3인 B-tree 구조

  39. Transaction Manager • A transaction • a collection of operations that performs a single logical function • Transaction-management component • ensures the database remains in a consistent (correct) state • system failures (e.g., power failures and operating system crashes) and transaction failures. • Concurrency-control manager • controls the interaction among the concurrent transactions 데이터베이스

  40. Transaction Manager 필수기능 • ACID property • Atomicity • all of a transaction be executed or none • Consistency • data meet user’s expectation • 한 개의 휴대폰은 한 명의 고객에게만 팔린다. • 연주회 좌석 100개에는 100명의 관객이 앉는다. • Isolation • When two or more transactions run concurrently, their effect must be isolated. • Durability • if a transaction completed, its effect should not get lost

  41. SQL • Structured Query Language • 데이터베이스를 access하여 manipulate할 수 있는 언어 • Select데이터 • From테이블명 • Where 조건

  42. The End

More Related