오늘도 잊지 않고 등장하는 Relational DBMS 구조
Relational Data Model이란?
- Structure : Table 같은 것
= DDL : Data Definition Language
- Operations : SQL같은 쿼리문
= Manipulative part = DML : Data Manipulation Language
- Constraints :
= Integrity part = DCL : Data Control Language
Relational Data Model 쓰는 이유?
- Set Processing objective : 집합기반의 Data이다.
- Logical / Physical aspect 구분이 명확하다.
- 단순한 구조 + Hive Level Language
Relational Model DB definition?
- A set of relations : 각 table들의 연관관계로 구성되어 있다.
--> data 표현을 High LV로 할 수 있는 유일한 방법은? 2차원 table이다.
- A relation(관계) made up of 2 parts
1) Schema(스키마) : Relation name + name & type of each column.
ex) STUDENT(sid:string, name:string, login:string, age:integer, gpa:real)-->relation이름과 col 이름+Type
2) Instance : a table, with rows and columns
=> # of rows = cardinality , # of fields(columns) = degree / arity.
A relation = A SET of rows(or tuples) (ex) all rows are distinct)
Schema : 맨 위에 표시 Students(sid:string, name:string ...)
가로 : Tuples ( = Records = Rows )
세로 : Fields ( = Attributes = Columns )
- Relation of table : attributes domain of type domain constrains
- Cardinaliry = 6개 ( 가로줄! TUPLE 개수 ), Degree( = arity ) = 5개( 세로줄! Field 개수 ), all row distinct
- Do all cols in a relation instance have to be distinct? : Key col이면 YES, 나머지 col은 No
결론-> DB엔 Entity와 entity 간의 관계 2가지를 넣는다(요 예제에선 Student) Schema, Instance
- Order of Tuple, Order of cols 는 중요하지 않다.
- Data addressing은 name/value 기준으로 하기 때문에 우리는 이를 Relational이라고 부르고, 이것이 Relational Model이 값을 다루는 방법이다.( <-> Tabular like excel)
- Colum(=attribute,filed) 순서가 바뀌거나 새로운 놈이 추가 / 삭제되어 Data처리가 가능하다 = Data Independence!
Creating Relations in SQL - DDL ( DATA DEFINITION LANGUAGE = SOC 中 Structure )
ex)
Create Table Students(sid : char(20), name: char(20), login : char(10), age : integer, gpa : real)
--> Student relation : for representing entity
Enrolled tabe ( to represent relationship) : course / students 정보를 담고 있다.
즉, 위 예시에서 Student / Course 는 Entity형성을 위한 Table이고 Enrolled는 그것이 아닌 관계를 만들기 위한 Table이다.
DDL 예시 추가 : View , Index creation , 즉 CREATE table/view/index 이런 거 전부 Definition Language
Modifying Relations - DML ( Data Manipulation Language )
ex) Insert a new tuple into a table : insert into students (sid,name,login) values(1234,'Marcus','mar@ee');
Delete all tuples satisfying some condition : delete from students S where s.name = 'SMITH'
Update a relation : Update students s set s,gpa = s.gpa-0.1 where s.gpa>=3.3
++)
Query Relations : Select * from students s where s.gpa>=3.3 and s.gpa < 25;
이렇게 그냥 필터링 해서 tuple(records = rows) 출력하는 것도 DML의 한 종류다.(SET-ORIENTED SEMANTICS!집합형태의 semantics다)
'Data Science > SQL' 카테고리의 다른 글
4. Relational Algebra and Calculus (0) | 2024.04.24 |
---|---|
3-2 Relation Model (0) | 2024.04.24 |
3-1 Relation Model (1) | 2024.04.24 |
2. SQL 기초 실습 코드 (0) | 2024.04.23 |
1. Over View of DB Systems (0) | 2024.04.20 |