## Database structure

The database structure is described in the next paragraphs (in PostgreSQL's syntax in this example):

### The customers table

The 'id' field is the primary key of this table.

    CREATE TABLE customers (
          id serial NOT NULL,
          name character varying(35) NOT NULL,
          default_served_by integer,
          country character varying(20),
          city character varying(30)
    );

### The orders table

Each row in the table represents an order passed by a customer. The customer is identified through a foreign key (the 'customer' field). The 'id' field is the primary key of this table.

    CREATE TABLE orders (
          id serial NOT NULL,
          customer integer NOT NULL,
          creation_date date DEFAULT now() NOT NULL,
          delivery_before date,
          delivery_date date
    );

### The order_contents table

Each row in the table represents an item in an order. The referenced order is identified through a foreign key (the 'order_id' field); the referenced item is identified through the 'product_ref' foreign key. This table has no primary key.

    CREATE TABLE order_contents (
          order_id integer NOT NULL,
          product_ref character varying(15) NOT NULL,
          quantity integer DEFAULT 1 NOT NULL,
          discount double precision DEFAULT 0 NOT NULL
    );

### The products table

Each row in the table represents an item which is sold and can be ordered. The 'ref field is the primary key of this table.

    CREATE TABLE products (
          ref character varying(15) NOT NULL,
          name character varying(20) NOT NULL,
          price double precision,
          wh_stored integer
    );