데이터베이스 및 테이블 작성 예제

다음 예제는 create 키워드를 사용하여 샘플 staff 데이터베이스를 작성하고 테이블을 정의합니다.

다음 OQL 문 예제는 컬럼 제한 조건 및 default 키워드의 사용법을 보여줍니다.

예제 1

create database staff;          // creates the staff database

다음 삽입은 managers 테이블을 정의합니다.

create table staff.managers
(
        EmployeeID                       int   NOT NULL   PRIMARY KEY,
        Name                             text  NOT NULL,
        Department                       text  default "Sales", 
        Gender                           text,
        Age                              int,
        unique ( EmployeeID )         // indicates that the data in the 
                                      // EmployeeID column must be unique.
);

managers 테이블의 경우:

  • EmployeeIDName 컬럼은 널(null)이 될 수 없습니다.
  • EmployeeID 컬럼은 1차 키이므로 고유해야 합니다.
  • 제공된 레코드에 대해 Department 컬럼에 어떤 값도 삽입되지 않으면 "Sales" 값을 사용합니다.

예제 2

다음 삽입은 staff.employees 테이블을 작성합니다.

create table staff.employees
(
        EmployeeID              int             NOT NULL   PRIMARY KEY,
        Name                    text            NOT NULL,
        Skills                  list type text,
        Gender                  text,
        Age                     int   // There is no comma here because this
                                      // is the last entry.
);

staff.employees 테이블의 경우:

  • EmployeeIDName 컬럼은 널(null)이 될 수 없습니다.
  • Skills 컬럼은 텍스트 문자열 목록입니다.

예제 3

다음 삽입은 staff.contractors 테이블을 작성합니다.

create table staff.contractors
(
        EmployeeID             int NOT NULL PRIMARY KEY,
        Name                   text NOT NULL,
        Gender                 text,
        Age                    int,
        ExtraInfo              object type vblist,
        volatile
);

staff.contractors 테이블의 경우:

  • ExtraInfo 컬럼에 varbind 목록이 포함됩니다.