You are on page 1of 5

CREATE TABLE COUNTRY ( COUNTRY_ID K ', 'ITA', 'FRA')), COUNTRY_NAME LANGUAGE );

CHAR(3) NOT NULL CHECK (COUNTRY_ID IN ('USA', 'CAN', 'MEX', 'U CHAR(45) NOT NULL, CHAR(30) NOT NULL

CREATE UNIQUE INDEX UK_COUNTRY ON COUNTRY ( COUNTRY_ID ASC ); CREATE TABLE CUSTOMER ( CUSTOMER_NBR COMPANY_NAME COUNTRY_ID K ', 'ITA')), STATE_ID REGION_ID SALES_MONTH01 SALES_MONTH02 SALES_MONTH03 USER_ID );

CHAR(3) NOT NULL, CHAR(30) NOT NULL, CHAR(3) NOT NULL CHECK (COUNTRY_ID IN ('USA', 'CAN', 'MEX', 'U CHAR(2) NOT NULL, CHAR(4) NOT NULL, DECIMAL(9) NOT NULL, DECIMAL(9,2) NOT NULL, DECIMAL(9,2) NOT NULL, CHAR(8) NOT NULL

CREATE UNIQUE INDEX PK_CUSTOMER ON CUSTOMER ( CUSTOMER_NBR ASC ); ALTER TABLE CUSTOMER ADD PRIMARY KEY (CUSTOMER_NBR); CREATE TABLE EMPLOYEE ( EMPLOYEE_ID EMPLOYEE_NAME EMPLOYEE_ADDRESS MANAGER_ID BANK_ID BRANCH_ID ACCOUNT# LAST_UPDATE );

CHAR(5) NOT NULL, VARCHAR(30) NOT NULL, CHAR(30) NOT NULL, CHAR(5) NOT NULL, CHAR(3) NOT NULL, CHAR(3) NOT NULL, CHAR(10) NOT NULL, CHAR(10) NOT NULL

CREATE UNIQUE INDEX PK_EMPLOYEE ON EMPLOYEE ( EMPLOYEE_ID ASC ); ALTER TABLE EMPLOYEE ADD PRIMARY KEY (EMPLOYEE_ID); CREATE TABLE ITEM (

ITEM_ID ITEM_DESCRIPTION UNIT_PRICE QTY_ON_HAND DESCRIPTION1 DESCRIPTION2 DESCRIPTION3 ITEM_STATUS LAST_UPDATE );

CHAR(3) NOT NULL, VARCHAR(30) NOT NULL, DECIMAL(9,2) NOT NULL CHECK (UNIT_PRICE > 0), DECIMAL(11,0) NOT NULL CHECK (QTY_ON_HAND > 0), CHAR(50) NOT NULL, CHAR(50) NOT NULL, CHAR(50) NOT NULL, CHAR(02) CHECK (ITEM_STATUS IN ('ENA')), CHAR(10) NOT NULL

CREATE UNIQUE INDEX NDX_ITM ON ITEM ( ITEM_ID ); CREATE INDEX NDX_ITM_STATUS ON ITEM ( ITEM_STATUS );

ASC

ASC

CREATE TABLE ITEM_HISTORY ( ITEM_ID CHAR(3) NOT NULL, OCCURRENCE_DATE DATE NOT NULL, UNIT_PRICE DECIMAL(9,2) NOT NULL ); CREATE UNIQUE INDEX PK_ITM_HST ON ITEM_HISTORY ( ITEM_ID ASC, OCCURRENCE_DATE ASC ); CREATE INDEX NDX_ITM_HST ON ITEM_HISTORY ( OCCURRENCE_DATE ASC, ITEM_ID ASC ); ALTER TABLE ITEM_HISTORY ADD PRIMARY KEY (ITEM_ID, OCCURRENCE_DATE); CREATE TABLE ORDER_TBL ( ORDER_NBR INVOICE_NBR CUSTOMER_NBR ORDER_DATE SALESMAN_ID COMPANY_NAME USER_ID );

CHAR(3) NOT NULL, CHAR(3) NOT NULL, CHAR(3), DATE NOT NULL, CHAR(3) NOT NULL, CHAR(25) NOT NULL, CHAR(8) NOT NULL

CREATE UNIQUE INDEX PK_ORD_TBL ON ORDER_TBL (

ORDER_NBR ); CREATE INDEX NDX_CST1 ON ORDER_TBL ( CUSTOMER_NBR ); CREATE INDEX NDX_CST2 ON ORDER_TBL ( CUSTOMER_NBR ORDER_DATE COMPANY_NAME ); ALTER TABLE ORDER_TBL ADD PRIMARY KEY (ORDER_NBR); CREATE TABLE ORDER_ITEM ( ORDER_NBR ITEM_ID QUANTITY UNIT_PRICE DISCOUNT );

ASC

ASC

ASC, ASC, ASC

CHAR(3) NOT NULL, CHAR(3) NOT NULL, DECIMAL(5) NOT NULL, DECIMAL(9,2) NOT NULL, DECIMAL(5,3) NOT NULL

CREATE UNIQUE INDEX NDX_ORD_ITM ON ORDER_ITEM ( ORDER_NBR ASC, ITEM_ID ASC ); CREATE TABLE REGION ( COUNTRY_ID STATE_ID REGION_ID REGION_NAME );

CHAR (3) NOT NULL, CHAR(2) NOT NULL, CHAR(4) NOT NULL, CHAR(45) NOT NULL

CREATE UNIQUE INDEX pk_region ON REGION ( COUNTRY_ID ASC, STATE_ID ASC, REGION_ID ASC ); CREATE UNIQUE INDEX uk_region ON REGION ( REGION_NAME ASC ); ALTER TABLE REGION ADD PRIMARY KEY (COUNTRY_ID, STATE_ID, REGION_ID); CREATE TABLE STATE (

COUNTRY_ID STATE_ID STATE_NAME );

CHAR (3) NOT NULL, CHAR(2) NOT NULL, CHAR(30) NOT NULL

CREATE UNIQUE INDEX UK_STATE ON STATE ( COUNTRY_ID ASC, STATE_ID ASC ); CREATE INDEX NDX_STATE1 ON STATE ( COUNTRY_ID ); CREATE TABLE SALESMAN ( SALESMAN_ID SALESMAN_NAME COUNTRY_ID ASSIGNED_STATE SALES_TARGET EMPLOYEE_ID );

ASC

CHAR(3) NOT NULL, CHAR(30) NOT NULL, CHAR (3) NOT NULL, CHAR (2) NOT NULL, DECIMAL(10,2) NOT NULL, CHAR(5) NOT NULL

CREATE UNIQUE INDEX UK_SALESMAN ON SALESMAN ( SALESMAN_ID ASC ); CREATE INDEX NDX_SAL_TARGET ON SALESMAN ( SALES_TARGET ASC ); CREATE TABLE VIP_CUSTOMER ( VIP_CUSTOMER_NBR CHAR(3) NOT NULL, ASSIGNED_SALESMAN CHAR(3) NOT NULL, ADDITIONAL_CREDIT DECIMAL(9,2) NOT NULL ); CREATE UNIQUE INDEX NDX_VIP_CST ON VIP_CUSTOMER ( VIP_CUSTOMER_NBR ASC ); CREATE TABLE INVOICE ( INVOICE_NBR ORDER_NBR INVOICE_DATE );

CHAR(3) NOT NULL, CHAR(3) NOT NULL, DATE NOT NULL

CREATE UNIQUE INDEX PK_INVOICE ON INVOICE ( INVOICE_NBR ASC );

ALTER TABLE INVOICE ADD PRIMARY KEY (INVOICE_NBR); ALTER TABLE EMPLOYEE ADD FOREIGN KEY EMP_EMP (MANAGER_ID) REFERENCES EMPLOYEE ON DELETE RESTRICT; ALTER TABLE ORDER_ITEM ADD FOREIGN KEY ITEM_ORDER (ORDER_NBR) REFERENCES ORDER_TBL ON DELETE RESTRICT; ALTER TABLE SALESMAN ADD FOREIGN KEY FK_SALEMAN_COUNTRY (COUNTRY_ID, ASSIGNED_STATE) REFERENCES STATE (COUNTRY_ID, STATE_ID) ON DELETE CASCADE; ALTER TABLE REGION ADD FOREIGN KEY FK_REGION_COUNTY (COUNTRY_ID) REFERENCES COUNTRY (COUNTRY_ID) ON DELETE CASCADE; ALTER TABLE STATE ADD FOREIGN KEY FK_STATE_COUNTRY (COUNTRY_ID) REFERENCES COUNTRY (COUNTRY_ID) ON DELETE CASCADE;