PostgreSQL

Скачать в pdf «PostgreSQL»


test(>


test(>


test(>


test(>


test(>


test(>


create


customer_id    INTEGER,


name    CHAR(30),


telephone    CHAR(20),


street    CHAR(40),


city    CHAR(25),


state    CHAR(2),


zipcode    CHAR(10),


country    CHAR(20)


);


CREATE TABLE employee (


employee_id    INTEGER,


name    CHAR(30),


hire_date    DATE


);


CREATE TABLE part (


part id


INTEGER,


name


CHAR(30),


cost


NUMERIC(8,2),


weight


float


salesorder (


order id


INTEGER,


customer id


INTEGER, — joins


to customer.customer ■


employee id


INTEGER, — joins


to employee.employee ■


part id


INTEGER, — joins


to part.part id


order_date


DATE,


ship_date


DATE,


payment


NUMERIC(8,2)


Keep in mind that all table and column names not protected by double quotes should consist of only letters, numbers, and the underscore character. Each name must start with a letter, not a number. Do not use punctuation, except the underscore, in your names. For example, address, office, and zipcode9 are valid names, but 2pair and my# are not.


The example in Figure 6.3 also shows the existence of a column named customerjd in two tables. This duplication occurs because the two columns contain the same type of number, a customer identification number. Giving them the same name clearly shows which columns join the tables together. If you wanted to use unique names, you could name the column salesorder_-customerjd or sales_cust_id. This choice makes the column names unique, but still documents the columns to be joined.

Скачать в pdf «PostgreSQL»