ILLINOIS INSTITUTE OF TECHNOLOGY
SALES DATABASE SCRIPT
ITM 421: INTRODUCTION TO DATABASES – DATA MODELING
ROBERT HENDRY
BY...
DROP TABLE OrderLine;
DROP TABLE Orders;
DROP TABLE Customer;
DROP TABLE Item;
DROP TABLE ShippingCo;
DROP TABLE SalesRep;...
);
INSERT INTO ITEM VALUES(111111111111,'Dell Adamo','Onyx',500.00,850.00,5);
INSERT INTO ITEM VALUES(111111111112,'Dell A...
CONSTRAINT FK_orderNumber FOREIGN KEY (orderNumber) REFERENCES
Orders(orderNumber),
CONSTRAINT FK_UPC FOREIGN KEY (UPC) RE...
Upcoming SlideShare
Loading in …5
×

Sales Database Script

348 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
348
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sales Database Script

  1. 1. ILLINOIS INSTITUTE OF TECHNOLOGY SALES DATABASE SCRIPT ITM 421: INTRODUCTION TO DATABASES – DATA MODELING ROBERT HENDRY BY SEAN P. MCBRIDE CHICAGO, IL 01 MARCH 2011 AD MAIOREM DEI GLORIAM
  2. 2. DROP TABLE OrderLine; DROP TABLE Orders; DROP TABLE Customer; DROP TABLE Item; DROP TABLE ShippingCo; DROP TABLE SalesRep; DROP TABLE ZIP; CREATE TABLE ZIP( ZIP NUMBER(5,0), city VARCHAR2(50) NOT NULL, state VARCHAR2(2) NOT NULL, CONSTRAINT PK_ZIP PRIMARY KEY(ZIP), CONSTRAINT check_state CHECK (state IN ('CA','NY','AL','DC','MD','IL')), CONSTRAINT check_ZIP CHECK (ZIP BETWEEN 01001 and 99950) ); INSERT INTO ZIP VALUES(94533,'Fairfield','CA'); INSERT INTO ZIP VALUES(10996,'West Point','NY'); INSERT INTO ZIP VALUES(36330,'Enterprise','AL'); INSERT INTO ZIP VALUES(20024,'Washington','DC'); INSERT INTO ZIP VALUES(20850,'Rockville','MD'); INSERT INTO ZIP VALUES(60301,'Oak Park','IL'); CREATE TABLE SalesRep( salesRepID NUMBER(*,0), lastName VARCHAR2(50) NOT NULL, CONSTRAINT PK_salesRepID PRIMARY KEY(salesRepID) ); INSERT INTO SalesRep VALUES(1,'Lords'); INSERT INTO SalesRep VALUES(2,'Chambers'); INSERT INTO SalesRep VALUES(3,'Lee'); CREATE TABLE ShippingCo( shippingCoID NUMBER(*,0), companyName VARCHAR2(50) NOT NULL, CONSTRAINT PK_shippingCoID PRIMARY KEY(shippingCoID) ); INSERT INTO ShippingCo VALUES(1,'UPS'); INSERT INTO ShippingCo VALUES(2,'USPS'); INSERT INTO ShippingCo VALUES(3,'FEDEX'); CREATE TABLE Item( UPC NUMBER(12,0), description VARCHAR2(200) NOT NULL, color VARCHAR2(20), stockingCost NUMBER(*,2) NOT NULL, unitListPrice NUMBER(*,2) NOT NULL, qtyInStock NUMBER(*,0) NOT NULL, CONSTRAINT PK_UPC PRIMARY KEY(UPC)
  3. 3. ); INSERT INTO ITEM VALUES(111111111111,'Dell Adamo','Onyx',500.00,850.00,5); INSERT INTO ITEM VALUES(111111111112,'Dell Adamo','Pearl',500.00,850.00,7); INSERT INTO ITEM VALUES(111111111113,'MacBook Air 2.0RAM 64SSD','Silver',750.00,999.99,43); CREATE TABLE Customer( customerID NUMBER(*,0), firstName VARCHAR2(50), lastName VARCHAR2(50), address VARCHAR2(100) NOT NULL, ZIP NUMBER(5,0) NOT NULL, phoneNumber NUMBER(10,0), CONSTRAINT PK_customerID PRIMARY KEY(customerID), CONSTRAINT FK_ZIP FOREIGN KEY (ZIP) REFERENCES ZIP(ZIP), CONSTRAINT check_phoneNumber CHECK (phoneNumber BETWEEN 2010000000 and 9999999999) ); INSERT INTO Customer VALUES(1,'Sean','McBride','100 Forest Pl.',60301,7078031111); INSERT INTO Customer VALUES(2,'Erica','McBride','100 Forest Pl.',60301,5402731111); INSERT INTO Customer VALUES(3,'Matt','Rix','100 Thayer Ave.',10996,2345678909); INSERT INTO Customer VALUES(4,'Ian','Morrison','212 Rucker Dr.',36330,2345678977); CREATE TABLE Orders( orderNumber NUMBER(*,0), customerID NUMBER(*,0) NOT NULL, orderDate DATE NOT NULL, shippingCoID NUMBER(*,0) NOT NULL, CONSTRAINT PK_orderNumber PRIMARY KEY(orderNumber), CONSTRAINT FK_customerID FOREIGN KEY (customerID) REFERENCES Customer(customerID), CONSTRAINT FK_shippingCoID FOREIGN KEY (shippingCoID) REFERENCES ShippingCo(shippingCoID) ); INSERT INTO Orders VALUES(1,1,'11-JAN-2011',2); INSERT INTO Orders VALUES(2,1,'14-JAN-2011',1); INSERT INTO Orders VALUES(3,3,'25-DEC-1985',3); INSERT INTO Orders VALUES(4,2,'01-JAN-2009',2); CREATE TABLE OrderLine( orderNumber NUMBER(*,0), UPC NUMBER(12,0), quantity NUMBER(*,0) NOT NULL, shipDate DATE NOT NULL, salesRepID NUMBER(*,0) NOT NULL, unitSalePrice NUMBER(*,2) NOT NULL, CONSTRAINT PK_orderNumber_UPC PRIMARY KEY(orderNumber,UPC),
  4. 4. CONSTRAINT FK_orderNumber FOREIGN KEY (orderNumber) REFERENCES Orders(orderNumber), CONSTRAINT FK_UPC FOREIGN KEY (UPC) REFERENCES Item(UPC), CONSTRAINT FK_salesRepID FOREIGN KEY (salesRepID) REFERENCES SalesRep(salesRepID) ); INSERT INTO OrderLine VALUES(1,111111111111,1,'12-JAN-2011',3,850.00); INSERT INTO OrderLine VALUES(1,111111111113,1,'13-JAN-2011',3,999.99); INSERT INTO OrderLine VALUES(2,111111111112,2,'16-JAN-2011',1,850.00); INSERT INTO OrderLine VALUES(3,111111111111,50,'05-JAN-1985',2,450.00); INSERT INTO OrderLine VALUES(4,111111111113,8,'11-JAN-2009',1,975.00); SET LINESIZE 132 SET PAGESIZE 1000 COLUMN firstName FORMAT A10 COLUMN Customer.lastName FORMAT A10 COLUMN to_char(Item.UPC,'999999999999') HEADING 'UPC' FORMAT A15 COLUMN description FORMAT A30 COLUMN SalesRep FORMAT A10 SELECT firstName, Customer.lastName, Orders.orderNumber, to_char(Item.UPC,'999999999999'), Description, Color, Quantity, SalesRep.lastName AS "SalesRep" FROM Customer,Orders,OrderLine,Item,SalesRep WHERE Customer.customerID=Orders.customerID AND Orders.orderNumber=OrderLine.orderNumber AND OrderLine.UPC=Item.UPC AND OrderLine.salesRepID=SalesRep.salesRepID;

×