Table creation

From Rosetta Code
Revision as of 14:55, 23 January 2007 by 209.63.105.137 (talk)
Task
Table creation
You are encouraged to solve this task according to the task description, using any language you may know.

In this task, the goal is to create a table to exemplify most commonly used data types and options.

PostgreSQL

-- This is a comment

CREATE SEQUENCE account_seq start 100;
CREATE TABLE account (
  account_id  int4 PRIMARY KEY DEFAULT nextval('account_seq'),
  created     date not null default now(),
  active      bool not null default 't',
  username    varchar(16) unique not null,
  age         int2,
  notes       text
);

CREATE TABLE account_note (
  account_id  int4 not null REFERENCES account,
  created     timestamp not null default now(),
  note        text not null,
  unique(account_id, note)
);