SeSac (2021-08 ~ 2021-12)/MySQL

MySQL - SQL 한방에 정리하기 Part 2 - DML, TCL

배워도끝이없네 2021. 9. 1. 11:30

DML(CRUD)

 

-insert

-select

  • like
  • in
  • between
  • distinct
  • count(distinct col1)
  • order by, rand()
  • order by col1 is null ASC, col1 ASC
  • limit a, limit a,b
  • group by,  having
  • case when ~else ~end
  • on duplicate key update... : unique한 키를 가진 컬럼을 duplicate 시킨다
  • join
    • inner join
    • outer join
      1. left outer join
      2. right outer join
      3. full outer join :mysql에서는 없기때문에 left outer join과 right outer join을 union걸어서 사용한다.
  • cross join : 카르테시안곱이 나온다 (select * from dept, emp) 실무에서는 존재하지 않는다

-update

-delete

 

order by를 rand()주게되면 불규칙하게 나오게 할 수 있다.

 

 

TCL : Commit & Rollback

 

"Session단위로 Tx는 제어됨"

 

start transanction; 하면 트랜젝션이 시작됨 (commit이나 rollback까지 유효)

 

DDL은 트랜젝션의 대상이 아니다(항상 오토커밋이 된다.)

 

save point a;로 트랜잭션의 롤백포인트를 만들수있다.