Courses/데이터베이스

01_Introduction to Database

noweahct 2025. 1. 22. 14:51

March, 2024

Data & Database

  • Data: 정형화되고 기록할만 한 가치가 있다고 판단되는 어떤 현상이나 사건, 아이디어에 대한 묘사
    • A formal description of an entity, event, phenomena, or idea
    • worth recording
  • Database (DB): 조직이나 개인이 사용하는 조작가능한, 저장된 데이터의 모음
    • An integrated collection of persistent data, representing the information of interest
    • representing the information of interest
    • for various programs that compose the computerized information system of an organization
    • Data are separated from the programs that use them
  • Database Management System (DBMS)
    • Set of programs to access the data

File Systems

  • File System: stores programs, data, documents or anything (in disk)
    • In the early days, database applications were built on top of file systems
  • Drawbacks of using the file system to store data
    • Data redundancy(중복) & 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 dependency: Data format and access methods depend on a particular application program
    • Data isolation(독차지): 데이터를 여러 사용자가 동시다발적으로 쓰지만, 독차지해서 쓰는 것처럼 느끼게 해줌
    • Integrity problems: Integrity constraints - hard to add new constraints or change existing ones
    • Atomicity(원자성) of updates: Failures may leave database in an inconsistent state with partial updates carried out
      • e.g., 500 있는 A 계좌, 300 있는 B 계좌가 있을 때 A에서 100 빼서 B로 옮기는 경우 • A에서 100 빼면 A가 400 • B에 100 더해서 B가 400
      • cf. automicity 보존 X • A에서 100 빼서 B에 100 넣다가 에러나서 A가 400, B가 300이 됨
    • Concurrent access by multiple users: Concurrent accesses are needed for performance, but uncontrolled concurrent access can lead to inconsistencies
    • Security problems: 보안을 보장하기 힘듦 (다양한 파일/접근경로, 다양한 프로그램의 이용)

DBMS

  • 데이터의 종속성과 중복성 문제를 해결함
  • 데이터베이스를 공유하고 관리하는 시스템
  • 장점: data redundancy의 최소화, data의 sharing, consistency 유지, integrity 유지, security 보장, standardization 용이, 전체 데이터 요구의 조정
  • 단점: 비용, 프로그램의 복잡화, 성능 상의 오버헤드

Levels of Abstraction

  • Physical level: describes how a record is stored
  • Logical level: describes data stored in database, and the relationships among the data

 

  • View level: application programs hide details of data types
    • Also views can hide information for security purposes

Data Independence Property

 

→ levels of abstraction 간의 independence가 보장되도록 함

 

1. Physical data independence: physical level - logical level

2. Logical data independence: logical level - view level

Data Model

  • Relational data model → Oracle, MySQL
    • 가장 널리 이용됨
    • relation (=table)에 기반한 모델로 사용이 편리하고 성능이 우수함
    • SQL 제공
  • Entity-Relationship (E-R) data model
    • database 설계에 주로 이용됨
    • Object-based (object-oriented and object-relational) data model

Relational Model의 주요 개념

  • Domain (type): attribute가 가질 수 있는 값의 집합
  • Attribute (column)
  • Tuple (row, record): set of values for attributes
  • Relation (table): set of tuples
  • Database: set of relations

*** Relation은 순서가 없다 (e.g., 집합 A={1, 2, 3}, B={3, 2, 1}은 같다 = 순서가 없다)

  • Schema: logical structure of the database
    • analogous to type information of a variable in a program
    • Physical Schema: database design at the physical level
    • Logical Schema: database design at the logical level
  • Instance: actual content of the database at a particular point in time
    • analogous to the value of a variable

Key

1. Key: Tuple을 구별하기 위한 Attribute 집합

  • Relation은 동일한 tuple이 있을 수 없음
  • 모든 tuple은 unique하다 (1개만 존재한다)

2. Superkey: relation에서 unique하게 tuple을 식별할 수 있는 attribute의 집합

3. Candidate Key: superkey 중에서 minimal한 key

  • minimal: 하나의 attribute이라도 빼면 더 이상 key가 아님

4. (Primary) Key (PK): Candidate key 중 하나 (relation을 정의할 때 선택

  • Entity Integrity: NULL이 될 수 없음

5. Foreign Key (FK): 타 relation을 참조하는 attribute

  • 단독으로 존재하지 않는다
  • 참조하는 relation에서 key가 아닐지라도, 참조되는 relation에서 pk인 경우
  • Referential Integrity: FK column의 모든 값이, 반드시 참조된 relation의 PK 값에 존재하거나 NULL이어야 함

NULL

  • special value for “unknown” or “undefined”
  • 숫자 0, 빈 문자열 (””)과는 다름
  • 모든 domain은 NULL값을 포함하고, NULL을 포함하지 않도록 명세할 수는 있음

Database Languages

  • Data Definition Language (DDL): database schema를 정의
    • Create / Drop
  • Data Manipulation Language (DML): database의 data를 조작
    • Retrieve / Insert / Delete / Change
    • schema는 불변 !
  • Data Control Language (DCL): database의 constraint를 제어

Database Languages (cont.)

  • Procedural (e.g., Relational Algebra) vs. Nonprocedural languages (e.g., SQL)Procedural Nonprocedural 
    Procedural Nonprocedural
    specify what data are needed and how to get those data declarative, specifty only what data are needed
    e.g., Relational Algebra e.g., Relational Calculus (→ 이론적으로만 존재), SQL

Structured Query Language (SQL)

  • application programs generally access databases through one of
    • Language extensions to allow embedded SQL
    • Application program interface which allow SQL queries to be sent to a database

Transaction Management

  • Transaction
    • a collection of operations that performs a single logical function in a database application
    • programmer is responsible for writing “correct” transactions
  • DBMS must ensure the ACID of each transaction
    • atomicity: all-or-nothing
    • consistency: same
    • isolation: alone
    • durability: effect should be persistent
  •