DB Chapter 6

|

Ch.6: The Database Language SQL


1.Simple Queries in SQL

Select: projection

From: data를 어디서 가져올 것인가?

Where: selection

select A as B: A를 B로 rename

Like %a: 마지막에 a로 끝나는 string을 select

Like %``s%: 중간에 ‘s가 들어가는 string을 select

union, intersection, difference(SQL에서는 except, Oracle에서는 minus)

3. Subqueries

함수안에 함수를 선언하는 느낌

Conditions Involving Relations

  • s IN R: s가 R에 있으면 True 아님 False
  • EXIST R: relation R이 empty가 아니면 True
  • s > ANY R: R에 s보다 큰 값이 1개라도 있으면 true
  • s > ALL R: R에 있는 모든 값이 s보다 커야 true

SQL Join Expression

  • A natural join B : natural join
  • A join B on a.x < b.x(조건) : theta join
  • A cross join B : product
  • A full(left, right) outer join B

기본적으로 select, from, where는 bag이고 union, intersection, difference는 set임.

bag를 set으로는 distinct를 사용하고 set을 bag로는 union all처럼 뒤에 all을 붙여주면 된다.

Aggregation, group by, having

DB modification: insert, delete, update 3가지가 전부

###

6. Transaction in SQL

Serializability : waiting until finish

기차좌석 예약할 때 하나의 seat를 예약하고 잇으면 그 seat는 다른 user는 사용할 수 없음.

Lock system임. 처음 들어간 사람이 lock걸음.

Commit과 rollback. Rollback은 스크린 올리는거고 commit은 스크린 내리는거(뭔소리람?)

Commit: we changed real data

Roollback: undo

Atomicity: 동시에 하는거

계좌에서 송금할 때 동시에 보내는 계좌에서는 돈이 빠져나가야하고 받는 계좌에서는 돈이 들어와야 함.

User와 bank의 SQL이 각각있는데 그거를 하나의 SQL로 합쳐서 다뤄야 동시에 파바박 됨. 이게 Atomicity.

transaction: process가 작업중인데 data값의 수정이 일어나는 것.

dirty read: 아직 commit되지 않은 data의 수정이 일어나 잘못된 값이 commit 되는 경우

계좌 송금의 경우 dirty read가 일어나면 critical 하지만, 좌석 예약의 경우 한 명의 사용자가 예약을 실패할 뿐 그게 다임.

DB5_7

이건 그냥 외우자 달달달달달~달 무슨달~