0% found this document useful (0 votes)
64 views1 page

Chapter 3: Selecting

The document contains SQL commands to create 6 tables: customer, employee, fin_code, product, sales_order, and sales_order_items. The customer table stores customer information. The employee table stores employee information including manager ID, department ID, address, and benefits. The fin_code table stores financial codes. The product table stores product data. The sales_order table links customers and employees to orders. And the sales_order_items table links order items to products and orders.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views1 page

Chapter 3: Selecting

The document contains SQL commands to create 6 tables: customer, employee, fin_code, product, sales_order, and sales_order_items. The customer table stores customer information. The employee table stores employee information including manager ID, department ID, address, and benefits. The fin_code table stores financial codes. The product table stores product data. The sales_order table links customers and employees to orders. And the sales_order_items table links order items to products and orders.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Chapter 3: Selecting 91

address CHAR ( 35 ) NOT NULL,


city CHAR ( 20 ) NOT NULL,
state CHAR ( 16 ) NULL,
zip CHAR ( 10 ) NULL,
phone CHAR ( 12 ) NOT NULL,
company_name CHAR ( 35 ) NULL,
PRIMARY KEY ( id ) );

CREATE TABLE employee (


emp_id INTEGER NOT NULL PRIMARY KEY,
manager_id INTEGER NULL,
emp_fname CHAR ( 20 ) NOT NULL,
emp_lname CHAR ( 20 ) NOT NULL,
dept_id INTEGER NOT NULL,
street CHAR ( 40 ) NOT NULL,
city CHAR ( 20 ) NOT NULL,
state CHAR ( 16 ) NULL,
zip_code CHAR ( 10 ) NULL,
phone CHAR ( 10 ) NULL,
status CHAR ( 2 ) NULL,
ss_number CHAR ( 11 ) NULL,
salary NUMERIC ( 20, 3 ) NOT NULL,
start_date DATE NOT NULL,
termination_date DATE NULL,
birth_date DATE NULL,
bene_health_ins CHAR ( 2 ) NULL,
bene_life_ins CHAR ( 2 ) NULL,
bene_day_care CHAR ( 2 ) NULL,
sex CHAR ( 2 ) NULL );

CREATE TABLE fin_code (


code CHAR ( 2 ) NOT NULL PRIMARY KEY,
type CHAR ( 10 ) NOT NULL,
description CHAR ( 50 ) NULL );

CREATE TABLE product (


id INTEGER NOT NULL,
name CHAR ( 15 ) NOT NULL,
description CHAR ( 30 ) NOT NULL,
size CHAR ( 18 ) NOT NULL,
color CHAR ( 6 ) NOT NULL,
quantity INTEGER NOT NULL,
unit_price NUMERIC ( 15, 2 ) NOT NULL,
PRIMARY KEY ( id ) );

CREATE TABLE sales_order (


id INTEGER NOT NULL DEFAULT AUTOINCREMENT,
cust_id INTEGER NOT NULL REFERENCES customer ( id ),
order_date DATE NOT NULL,
fin_code_id CHAR ( 2 ) NULL REFERENCES fin_code ( code ),
region CHAR ( 7 ) NULL,
sales_rep INTEGER NOT NULL REFERENCES employee ( emp_id ),
PRIMARY KEY ( id ) );

CREATE TABLE sales_order_items (


id INTEGER NOT NULL REFERENCES sales_order ( id ),
line_id SMALLINT NOT NULL,
prod_id INTEGER NOT NULL REFERENCES product ( id ),
quantity INTEGER NOT NULL,
ship_date DATE NOT NULL,
PRIMARY KEY ( id, line_id ) );

You might also like