Integrity Constraints: 두 판 사이의 차이

youngwiki
15번째 줄: 15번째 줄:


==Constraints on a Single Relation==
==Constraints on a Single Relation==
[[<code>create table</code>]] 명령을 통해서 정의할 있는
[[SQL data definition#Basic Schema Definition|create table]] 명령은 테이블을 정의하는 것 외에도 integrity constraint를 포함할 있다. 이때 primary key 외에도 다음과 같은 integrity constraint가 포함될 수 있다:
* not null
* unique
* check(<조건>)
해당 문서에서는 위 constraint에 대해 설명한다.
 
===Not null constraint===
null 값은 모든 속성(atrribute)의 도메인에 포함되기 때문에
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">



2025년 4월 9일 (수) 13:35 판

상위 문서: SQL

개요

Integrity constraint는 승인된 사용자에 의해 데이터베이스에 적용된 갱신(update)에 의한 변경 데이터의 일관성(consistency)를 잃지 않도록 보장해준다. 즉, integrity constraint는 데이터베이스를 우발적인 손상으로부터 보호하는 역할을 한다.[1] Integrity constraint의 예는 다음과 같다:

  • 강사(instructor)의 이름은 null일 수 없다.
  • 두 명의 강사가 동일한 ID를 가질 수 없다.
  • course 릴레이션의 모든 학과(department) 이름은 department 릴레이션에 존재해야 한다.
  • 학과의 예산은 반드시 $0.00보다 커야 한다.

일반적으로 데이터베이스에 관련된 임의의 논리 조건(predicate)은 integrity constraint가 될 수 있다. 하지만 어떤 조건은 검사 비용이 높을 수 있기 때문에 대부분의 DBMS는 비용이 적게 드는(minimal overhead) constraint 만을 명시하도록 한다.
Integrity constraint는 보통 데이터베이스 스키마(schema) 설계 과정의 일부로 인식되며, create table 명령의 일부로 릴레이션을 생성할 때 선언된다. 또한 아래와 같이 기존 릴레이션에 integrity constraint를 추가할 수 있다.

alter table <table name> add <constraint> ...

Integrity constraint에는 primary key constraintforeign key constraint도 존재하지만 해당 문서에는 다른 종류의 constraint에 대해 알아본다.

Constraints on a Single Relation

create table 명령은 테이블을 정의하는 것 외에도 integrity constraint를 포함할 수 있다. 이때 primary key 외에도 다음과 같은 integrity constraint가 포함될 수 있다:

  • not null
  • unique
  • check(<조건>)

해당 문서에서는 위 constraint에 대해 설명한다.

Not null constraint

null 값은 모든 속성(atrribute)의 도메인에 포함되기 때문에

각주

  1. 이는 무단 사용자의 접근을 막는 security constraint와는 대조적이다.