오뚝이개발자

[DB] CH5. Advanced SQL(고급 SQL) - JDBC, ODBC, 트리거(Trigger) 본문

CS 기초/DB

[DB] CH5. Advanced SQL(고급 SQL) - JDBC, ODBC, 트리거(Trigger)

땅어 2020. 11. 2. 15:58
728x90
300x250

 

JDBC, ODBC란?

  • 프로그램(Application Program)이 DB 서버와 interact하기 위한 API()
  • 사용하면 다음과 같은 작업을 할 수 있다.
    • DB서버에 Connect
    • DB서버에 SQL command 요청
    • 특정 tuple 가져오기
  • ODBC(Open Database Connectivity) - works with C, C++, C# and Visual Basic
  • JDBC(Java Database Connectivity) - works with Java

Trigger란?

  • DB modification의 side-effect로 system에 의해 자동으로 실행되는 statement
  • trigger가 실행되는 condition과 실행될 때 할 action을 정해줘야 함
  • 사용예시) section에 새 데이터를 insert하려는데 해당 데이터의 time_slot_id가 time_slot의 time_slot_id에 존재하는지 확인하고 싶다고 하자. 하지만, time_slot_id가 time_slot의 primary key가 아니기 때문에 section에서 time_slot으로의 foreign key constraint을 만들 순 없다. 이 때, 아래 예시와 같이 trigger를 사용해 enfoce integrity constraints를 할 수 있다.
    • cf) after대신 before를 사용해 조건을 만들 수도 있다. 혹은 after update of takes on grade와 같이 on을 사용해 특정 attribute에 대한 조건을 만드는 것도 가능하다.

trigger 사용 예시

728x90
300x250
Comments