SlideShare une entreprise Scribd logo
1  sur  5
SQL Database Schema and stored procedures created by
Christopher Kaczor
This code is only for use with Microsoft SQL Server
/* When you open Microsoft SQL Server right click Databases in the object explorer then
click “New Database”, name the database Organic_Gardens. Create a new query and make sure
you choose Organic Gardens from the available databases list or type USE Organic_Gardens
and under that GO, run the query. The schema and later stored procedures are divided into
parts which need to be installed in the proper numerical order to work. Copy and paste
the code into Microsoft SQL server following the numbers from lowest to greatest. Each
part is divided by the -------- divider. */
-------------------------------------------------------------------------------------PART
1----------------------------------------------------------------------------------------
----------
---Copy and past this in first up to the bottom line.
CREATE TABLE Vendors (
item_UPC INT NOT NULL
PRIMARY KEY,
vend_inv_stock INT NOT NULL,
vendor_name VARCHAR(50) NOT NULL,
vend_country VARCHAR(15) NOT NULL,
vend_state CHAR(2) NOT NULL,
vend_city VARCHAR(20) NOT NULL,
vend_zip VARCHAR(15) NOT NULL,
vend_address VARCHAR(20) NOT NULL,
vend_phone VARCHAR(20) NOT NULL,
date_ordered DATE NULL,
on_order INT NULL,
);
CREATE TABLE Items (
item_UPC INT NOT NULL REFERENCES
Vendors (item_UPC),
item_name VARCHAR(50) NULL,
item_price MONEY NOT NULL,
aisle INT NOT NULL,
store_on_hand INT NOT NULL,
);
CREATE TABLE OnlineOrders (
item_UPC INT NOT NULL REFERENCES
Vendors (item_UPC),
online_price MONEY NOT NULL,
online_custid VARCHAR(50) NOT NULL PRIMARY KEY,
);
CREATE TABLE OnlineCustomers (
online_custid VARCHAR(50) NOT NULL REFERENCES
OnlineOrders(online_custid),
cust_name VARCHAR(50) NOT NULL,
cust_address VARCHAR(50) NOT NULL,
cust_city VARCHAR(20) NOT NULL,
cust_country VARCHAR(20) NOT NULL,
cust_state CHAR(2) NOT NULL,
cust_zip VARCHAR(15) NOT NULL,
cust_email VARCHAR(50) NULL,
cust_phone VARCHAR(20) NULL,
order_date DATE NOT NULL,
);
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
----------
--------------------------------------------------------------------------------------
PART 2-----------------------------------------------------------------------------------
-----------------------------------------------------------------------
--Copy and past this in second up to the bottom line.
CREATE PROC AddVendor (@itemUPC INT, @vendstock INT, @vendname VARCHAR(50), @vendcountry
VARCHAR(15), @vendstate CHAR(2), @vendcity VARCHAR(20), @vendzip VARCHAR(15), @vendphone
VARCHAR(20), @vend_address VARCHAR(20), @dateord DATE, @onorder INT)
AS
BEGIN
INSERT INTO Vendors (item_UPC, vend_inv_stock, vendor_name, vend_country, vend_state,
vend_city, vend_zip, vend_phone, vend_address, date_ordered, on_order)
VALUES (@itemUPC, @vendstock, @vendname, @vendcountry, @vendstate, @vendcity, @vendzip,
@vendphone, @vend_address, @dateord, @onorder);
END
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
----------------------------------------------------------------------------------PART 3-
-----------------------------------------------------------------------------------------
------------------------------------------------------------------------
------Copy and past this in third up to the bottom line.
EXEC AddVendor 1000000001, 6597, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057',
'256-8754-2594', '456 Apple St', '05-05-2015', 10528
EXEC AddVendor 1000000002, 5811, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057',
'256-8754-2594', '456 Apple St', '05-05-2015', 9562
EXEC AddVendor 1000000003, 8745, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057',
'256-8754-2594', '456 Apple St', '05-05-2015', 108
EXEC AddVendor 1000000004, 8521, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057',
'256-8754-2594', '456 Apple St', '05-05-2015', 1851
EXEC AddVendor 1000000005, 9657, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057',
'256-8754-2594', '456 Apple St', '05-05-2015', 854
EXEC AddVendor 1000000006, 2562, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057',
'256-8754-2594', '456 Apple St', '05-05-2015', 10528
EXEC AddVendor 1000000007, 4548, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057',
'256-8754-2594', '456 Apple St', '05-05-2015', 5684
EXEC AddVendor 1000000008, 2857, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057',
'256-8754-2594', '456 Apple St', '05-05-2015', 195
EXEC AddVendor 1000000009, 8752, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057',
'256-8754-2594', '456 Apple St', '05-05-2015', 528
EXEC AddVendor 1000000010, 10587, 'Organic_Produce', 'USA', 'PA', 'West Chester',
'19057', '256-8754-2594', '456 Apple St', '05-05-2015', 8754
EXEC AddVendor 1000000011, 96525, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2',
'785-8452-9672', '687 rue agricole', '06-05-2015', 100
EXEC AddVendor 1000000012, 8752, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2',
'785-8452-9672', '687 rue agricole', '07-05-2015', 100
EXEC AddVendor 1000000013, 8520, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2',
'785-8452-9672', '687 rue agricole', '08-05-2015', 100
EXEC AddVendor 1000000014, 7842, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2',
'785-8452-9672', '687 rue agricole', '09-05-2015', 100
EXEC AddVendor 1000000015, 8541, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2',
'785-8452-9672', '687 rue agricole', '10-05-2015', 100
EXEC AddVendor 1000000016, 20000, 'Organic Dry Foods', 'USA', 'FL', 'Miami', '55674',
'524-965-8752', '789 Orange St', '08-09-2015', 4152
EXEC AddVendor 1000000017, 30000, 'Organic Dry Foods', 'USA', 'FL', 'Miami', '55674',
'524-965-8752', '789 Orange St', '08-09-2015', 9875
EXEC AddVendor 1000000018, 40000, 'Organic Dry Foods', 'USA', 'FL', 'Miami', '55674',
'524-965-8752', '789 Orange St', '08-09-2015', 5486
EXEC AddVendor 1000000019, 50000, 'Organic Dry Foods', 'USA', 'FL', 'Miami', '55674',
'524-965-8752', '789 Orange St', '08-09-2015', 5846
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
---------
------------------------------------------------------------------------------Part 4-----
-----------------------------------------------------------------------------------------
-------
---Copy and past this in fourth up to the bottom line.
CREATE PROC AddItems (@itemUPC INT, @itemname VARCHAR(50), @itemprice MONEY, @aisle INT,
@storeonhand INT)
AS
BEGIN
INSERT INTO Items (item_UPC, item_name, item_price, aisle, store_on_hand)
VALUES (@itemUPC, @itemname, @itemprice, @aisle, @storeonhand)
END
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-------
--------------------------------------------------------------------------Part 5---------
-----------------------------------------------------------------------------------------
----------
----Copy and past this in fifth up to the bottom line.-----------------------------------
-----------------------------------------------------------------------------------------
-----------
EXEC AddItems 1000000001, 'Apples| 3 lb', '0.30', 1, 70;
EXEC AddItems 1000000002, 'Oranges| 2 lb', '0.75', 1, 70;
EXEC AddItems 1000000003, 'Watermelons', '1.00', 1, 70;
EXEC AddItems 1000000004, 'Kiwis| per bag', '2.90', 1, 43;
EXEC AddItems 1000000005, 'Plums| 2 lb', '0.40', 1, 70;
EXEC AddItems 1000000006, 'Grapes| per bag', '2.30', 1, 20;
EXEC AddItems 1000000007, 'Bananas| per bag', '2.70', 1, 40;
EXEC AddItems 1000000008, 'Lettuce', '2.50', 2, 70;
EXEC AddItems 1000000009, 'Potatoes| per bag', '2.00', 2, 40;
EXEC AddItems 1000000010, 'Cabbage', '3.00', 2, 40;
EXEC AddItems 1000000011, 'Steak 4 pack', '25.00', 3, 70;
EXEC AddItems 1000000012, 'Pork 4 pack', '15.00', 3, 70;
EXEC AddItems 1000000013, 'Chicken', '9.57', 3, 70;
EXEC AddItems 1000000014, 'Ham', '8.00', 3, 70;
EXEC AddItems 1000000015, 'Turkey', '25.95', 3, 70;
EXEC AddItems 1000000016, 'Cereal', '3.00', 4, 30;
EXEC AddItems 1000000017, 'Dried Oats', '2.50', 4, 70;
EXEC AddItems 1000000018, 'Nuts| 2 lb', '1.36', 4, 1568;
EXEC AddItems 1000000019, 'Cashews| 2 lb', '6.99', 4, 8524;
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
---------------
-----------------------------------------------------------------------------------------
--Part 6---------------------------------------------------------------------------------
--------------
---------Copy and past this in sixth up to the bottom line.------------------------------
-----------------------------------------------------------------------------------------
----------------
CREATE PROC AddOnlineOrders (@itemUPC INT, @onlprice MONEY, @onlcustid VARCHAR(50))
AS
BEGIN
INSERT INTO OnlineOrders (item_UPC, online_price, online_custid)
VALUES (@itemUPC, @onlprice, @onlcustid)
END
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
----------------------------
--------------------------------------------------------------------------------Part 7---
-----------------------------------------------------------------------------------------
---------------------------
----Copy and past this in seventh up to the bottom line.---------------------------------
-----------------------------------------------------------------------------------------
-------------
EXEC AddOnlineOrders 1000000011, 29.99, 'steak_lover';
EXEC AddOnlineOrders 1000000002, 0.75, 'j_aime_des_oranges';
EXEC AddOnlineOrders 1000000009, 2.00, 'picky_potato';
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-------------------
---------------------------------------------------------------------------------------
Part 8-----------------------------------------------------------------------------------
-------------------------------
----Copy and past this in eighth up to the bottom line.----------------------------------
-----------------------------------------------------------------------------------------
------------
CREATE PROC AddOnlineCust (@onlcustid VARCHAR(50), @custname VARCHAR(50), @custaddress
VARCHAR(50), @custcity VARCHAR(20), @custcountry VARCHAR(20), @custstate CHAR(2),
@custzip VARCHAR(15), @custemail VARCHAR(50), @custphone VARCHAR(20), @orderdate DATE)
AS
BEGIN
INSERT INTO OnlineCustomers (online_custid, cust_name, cust_address, cust_city,
cust_country, cust_state, cust_zip, cust_email, cust_phone, order_date)
VALUES (@onlcustid, @custname, @custaddress, @custcity, @custcountry, @custstate,
@custzip, @custemail, @custphone, @orderdate)
END
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-------------------------------------
--------------------------------------------------------------------------------------
Part 9-----------------------------------------------------------------------------------
-----------------------------------
----Copy and past this in ninth up to the bottom line.-----------------------------------
-----------------------------------------------------------------------------------------
---------------
EXEC AddOnlineCust 'steak_lover', 'Christopher Steakous', '156 Steak Rd', 'Philadelphia',
'USA', 'PA', '19065', 'loverofsteak@steak.com', '215-584-9638', '01-01-2016'
EXEC AddOnlineCust 'j_aime_des_oranges', 'Philipe Orange', '352 rue Beauvoir', 'Quebec',
'Canada', 'QC', 'H2A 6D3 ', 'philipe@rodgers.com', '658-521-9632', '01-01-2016'
EXEC AddOnlineCust 'picky_potato', 'Bob Prank', '169 Prank Rd', 'New York City', 'USA',
'NY', '56821', 'bob@bob.com', '785-565-9274', '01-01-2016'
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--------------------
-------------------------------------------------------------------------------MISC
Stored Procedures for analysis-----------------------------------------------------------
-----------
--This stored procedures allows you to count how many orders a customer has placed in the
system
CREATE PROC NumOrderPerCust (@custname VARCHAR(50))
AS
BEGIN
SELECT OC.cust_name, COUNT(OO.online_custid) AS num_of_orders
FROM OnlineCustomers AS OC FULL OUTER JOIN OnlineOrders AS OO
ON OC.online_custid = OO.online_custid
WHERE OC.cust_name LIKE '%' + @custname + '%'
GROUP BY OC.cust_name
END
--This stored procedure allows you to see how many overall orders are in the system
CREATE PROC OrdersInSystem
AS
SELECT OC.cust_name, COUNT(OO.online_custid) AS num_of_orders
FROM OnlineCustomers AS OC FULL OUTER JOIN OnlineOrders AS OO
ON OC.online_custid = OO.online_custid
GROUP BY OC.cust_name

Contenu connexe

En vedette

Agenda Cultural Calp 2016 (julio agosto)
Agenda Cultural Calp 2016 (julio agosto) Agenda Cultural Calp 2016 (julio agosto)
Agenda Cultural Calp 2016 (julio agosto) TurismoCalp
 
Efinance (Finanzas en Linea)
Efinance (Finanzas en Linea)Efinance (Finanzas en Linea)
Efinance (Finanzas en Linea)Oswaldo Monagas
 
Cuando todo prece malo salmos 77 ibe callao
Cuando todo prece malo salmos 77 ibe callaoCuando todo prece malo salmos 77 ibe callao
Cuando todo prece malo salmos 77 ibe callaoIBE Callao
 
unidad 1. Recursos tecnológicos para el aprendizaje.
unidad 1. Recursos tecnológicos para el aprendizaje.unidad 1. Recursos tecnológicos para el aprendizaje.
unidad 1. Recursos tecnológicos para el aprendizaje.kathiaagd
 
Arte en la historia del deporte Luis J. Jimenez
Arte en la historia del deporte Luis J. JimenezArte en la historia del deporte Luis J. Jimenez
Arte en la historia del deporte Luis J. JimenezLuis José Jiménez Laín
 
Distribuição da População Mundial
Distribuição da População MundialDistribuição da População Mundial
Distribuição da População MundialDiogo Mateus
 
Sammanfattning utav fuego
Sammanfattning utav fuegoSammanfattning utav fuego
Sammanfattning utav fuegoulrsve
 
Link Belt ICE 180 M Military Manual tm 5-3895-265-14
Link Belt  ICE 180 M Military Manual tm 5-3895-265-14Link Belt  ICE 180 M Military Manual tm 5-3895-265-14
Link Belt ICE 180 M Military Manual tm 5-3895-265-14Dennis Gigoux
 

En vedette (15)

LaShondra Resume.1
LaShondra Resume.1LaShondra Resume.1
LaShondra Resume.1
 
Agenda Cultural Calp 2016 (julio agosto)
Agenda Cultural Calp 2016 (julio agosto) Agenda Cultural Calp 2016 (julio agosto)
Agenda Cultural Calp 2016 (julio agosto)
 
KM 01 to 153
KM 01 to 153KM 01 to 153
KM 01 to 153
 
Efinance (Finanzas en Linea)
Efinance (Finanzas en Linea)Efinance (Finanzas en Linea)
Efinance (Finanzas en Linea)
 
GCE_Visualising Portfolio
GCE_Visualising PortfolioGCE_Visualising Portfolio
GCE_Visualising Portfolio
 
AL-SC-1209-Minitech
AL-SC-1209-MinitechAL-SC-1209-Minitech
AL-SC-1209-Minitech
 
Cuando todo prece malo salmos 77 ibe callao
Cuando todo prece malo salmos 77 ibe callaoCuando todo prece malo salmos 77 ibe callao
Cuando todo prece malo salmos 77 ibe callao
 
Santosh_Bokade
Santosh_BokadeSantosh_Bokade
Santosh_Bokade
 
unidad 1. Recursos tecnológicos para el aprendizaje.
unidad 1. Recursos tecnológicos para el aprendizaje.unidad 1. Recursos tecnológicos para el aprendizaje.
unidad 1. Recursos tecnológicos para el aprendizaje.
 
Arte en la historia del deporte Luis J. Jimenez
Arte en la historia del deporte Luis J. JimenezArte en la historia del deporte Luis J. Jimenez
Arte en la historia del deporte Luis J. Jimenez
 
Distribuição da População Mundial
Distribuição da População MundialDistribuição da População Mundial
Distribuição da População Mundial
 
Sammanfattning utav fuego
Sammanfattning utav fuegoSammanfattning utav fuego
Sammanfattning utav fuego
 
Diccionario Pictorico
Diccionario PictoricoDiccionario Pictorico
Diccionario Pictorico
 
Jamal Path to Investing
Jamal Path to InvestingJamal Path to Investing
Jamal Path to Investing
 
Link Belt ICE 180 M Military Manual tm 5-3895-265-14
Link Belt  ICE 180 M Military Manual tm 5-3895-265-14Link Belt  ICE 180 M Military Manual tm 5-3895-265-14
Link Belt ICE 180 M Military Manual tm 5-3895-265-14
 

Similaire à Organic Gardens SQL Database Schema By Christopher Kaczor

Alvedit programs
Alvedit programsAlvedit programs
Alvedit programsmcclintick
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Hemant K Chitale
 
Metadata Matters
Metadata MattersMetadata Matters
Metadata Mattersafa reg
 
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity VerificationQRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity VerificationArcBlock
 
create_workbook_store.sql-- create_store.sql-- Introcution,.docx
create_workbook_store.sql-- create_store.sql-- Introcution,.docxcreate_workbook_store.sql-- create_store.sql-- Introcution,.docx
create_workbook_store.sql-- create_store.sql-- Introcution,.docxfaithxdunce63732
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所Hiroshi Sekiguchi
 
Starting from the database used in Project 1 (see the slightly cha.docx
Starting from the database used in Project 1 (see the slightly cha.docxStarting from the database used in Project 1 (see the slightly cha.docx
Starting from the database used in Project 1 (see the slightly cha.docxdessiechisomjj4
 
Orastat line command
Orastat line commandOrastat line command
Orastat line commandalbertinous
 
May Woo Bi Portfolio
May Woo Bi PortfolioMay Woo Bi Portfolio
May Woo Bi Portfoliomaywoo
 
Alv interactive ABAPreport
Alv interactive ABAPreportAlv interactive ABAPreport
Alv interactive ABAPreportRavi Kanudawala
 
Loopback.vhd
Loopback.vhdLoopback.vhd
Loopback.vhdsachindb9
 
Oracle Web Adi For upload item master
Oracle Web Adi For upload item masterOracle Web Adi For upload item master
Oracle Web Adi For upload item masterAhmed Elshayeb
 

Similaire à Organic Gardens SQL Database Schema By Christopher Kaczor (20)

DBMS LAB
DBMS LABDBMS LAB
DBMS LAB
 
Alvedit programs
Alvedit programsAlvedit programs
Alvedit programs
 
Quick reference for hql
Quick reference for hqlQuick reference for hql
Quick reference for hql
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)
 
Zmalv output type_v1.1
Zmalv output type_v1.1Zmalv output type_v1.1
Zmalv output type_v1.1
 
Metadata Matters
Metadata MattersMetadata Matters
Metadata Matters
 
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity VerificationQRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
 
create_workbook_store.sql-- create_store.sql-- Introcution,.docx
create_workbook_store.sql-- create_store.sql-- Introcution,.docxcreate_workbook_store.sql-- create_store.sql-- Introcution,.docx
create_workbook_store.sql-- create_store.sql-- Introcution,.docx
 
5 Cool Things About SQL
5 Cool Things About SQL5 Cool Things About SQL
5 Cool Things About SQL
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所
 
Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0
 
Starting from the database used in Project 1 (see the slightly cha.docx
Starting from the database used in Project 1 (see the slightly cha.docxStarting from the database used in Project 1 (see the slightly cha.docx
Starting from the database used in Project 1 (see the slightly cha.docx
 
Orastat line command
Orastat line commandOrastat line command
Orastat line command
 
May Woo Bi Portfolio
May Woo Bi PortfolioMay Woo Bi Portfolio
May Woo Bi Portfolio
 
SAV
SAVSAV
SAV
 
Alv interactive ABAPreport
Alv interactive ABAPreportAlv interactive ABAPreport
Alv interactive ABAPreport
 
Loopback.vhd
Loopback.vhdLoopback.vhd
Loopback.vhd
 
Oracle Web Adi For upload item master
Oracle Web Adi For upload item masterOracle Web Adi For upload item master
Oracle Web Adi For upload item master
 
Msbi
MsbiMsbi
Msbi
 
my_project
my_projectmy_project
my_project
 

Organic Gardens SQL Database Schema By Christopher Kaczor

  • 1. SQL Database Schema and stored procedures created by Christopher Kaczor This code is only for use with Microsoft SQL Server /* When you open Microsoft SQL Server right click Databases in the object explorer then click “New Database”, name the database Organic_Gardens. Create a new query and make sure you choose Organic Gardens from the available databases list or type USE Organic_Gardens and under that GO, run the query. The schema and later stored procedures are divided into parts which need to be installed in the proper numerical order to work. Copy and paste the code into Microsoft SQL server following the numbers from lowest to greatest. Each part is divided by the -------- divider. */ -------------------------------------------------------------------------------------PART 1---------------------------------------------------------------------------------------- ---------- ---Copy and past this in first up to the bottom line. CREATE TABLE Vendors ( item_UPC INT NOT NULL PRIMARY KEY, vend_inv_stock INT NOT NULL, vendor_name VARCHAR(50) NOT NULL, vend_country VARCHAR(15) NOT NULL, vend_state CHAR(2) NOT NULL, vend_city VARCHAR(20) NOT NULL, vend_zip VARCHAR(15) NOT NULL, vend_address VARCHAR(20) NOT NULL, vend_phone VARCHAR(20) NOT NULL, date_ordered DATE NULL, on_order INT NULL, ); CREATE TABLE Items ( item_UPC INT NOT NULL REFERENCES Vendors (item_UPC), item_name VARCHAR(50) NULL, item_price MONEY NOT NULL, aisle INT NOT NULL, store_on_hand INT NOT NULL, ); CREATE TABLE OnlineOrders ( item_UPC INT NOT NULL REFERENCES Vendors (item_UPC), online_price MONEY NOT NULL, online_custid VARCHAR(50) NOT NULL PRIMARY KEY, ); CREATE TABLE OnlineCustomers ( online_custid VARCHAR(50) NOT NULL REFERENCES OnlineOrders(online_custid), cust_name VARCHAR(50) NOT NULL, cust_address VARCHAR(50) NOT NULL, cust_city VARCHAR(20) NOT NULL,
  • 2. cust_country VARCHAR(20) NOT NULL, cust_state CHAR(2) NOT NULL, cust_zip VARCHAR(15) NOT NULL, cust_email VARCHAR(50) NULL, cust_phone VARCHAR(20) NULL, order_date DATE NOT NULL, ); ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- ---------- -------------------------------------------------------------------------------------- PART 2----------------------------------------------------------------------------------- ----------------------------------------------------------------------- --Copy and past this in second up to the bottom line. CREATE PROC AddVendor (@itemUPC INT, @vendstock INT, @vendname VARCHAR(50), @vendcountry VARCHAR(15), @vendstate CHAR(2), @vendcity VARCHAR(20), @vendzip VARCHAR(15), @vendphone VARCHAR(20), @vend_address VARCHAR(20), @dateord DATE, @onorder INT) AS BEGIN INSERT INTO Vendors (item_UPC, vend_inv_stock, vendor_name, vend_country, vend_state, vend_city, vend_zip, vend_phone, vend_address, date_ordered, on_order) VALUES (@itemUPC, @vendstock, @vendname, @vendcountry, @vendstate, @vendcity, @vendzip, @vendphone, @vend_address, @dateord, @onorder); END ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------PART 3- ----------------------------------------------------------------------------------------- ------------------------------------------------------------------------ ------Copy and past this in third up to the bottom line. EXEC AddVendor 1000000001, 6597, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 10528 EXEC AddVendor 1000000002, 5811, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 9562 EXEC AddVendor 1000000003, 8745, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 108 EXEC AddVendor 1000000004, 8521, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 1851 EXEC AddVendor 1000000005, 9657, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 854 EXEC AddVendor 1000000006, 2562, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 10528 EXEC AddVendor 1000000007, 4548, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 5684 EXEC AddVendor 1000000008, 2857, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 195 EXEC AddVendor 1000000009, 8752, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 528 EXEC AddVendor 1000000010, 10587, 'Organic_Produce', 'USA', 'PA', 'West Chester', '19057', '256-8754-2594', '456 Apple St', '05-05-2015', 8754 EXEC AddVendor 1000000011, 96525, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2', '785-8452-9672', '687 rue agricole', '06-05-2015', 100
  • 3. EXEC AddVendor 1000000012, 8752, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2', '785-8452-9672', '687 rue agricole', '07-05-2015', 100 EXEC AddVendor 1000000013, 8520, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2', '785-8452-9672', '687 rue agricole', '08-05-2015', 100 EXEC AddVendor 1000000014, 7842, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2', '785-8452-9672', '687 rue agricole', '09-05-2015', 100 EXEC AddVendor 1000000015, 8541, 'Viandes Bios', 'Canada', 'QC', 'St Anicet', 'H1A 5M2', '785-8452-9672', '687 rue agricole', '10-05-2015', 100 EXEC AddVendor 1000000016, 20000, 'Organic Dry Foods', 'USA', 'FL', 'Miami', '55674', '524-965-8752', '789 Orange St', '08-09-2015', 4152 EXEC AddVendor 1000000017, 30000, 'Organic Dry Foods', 'USA', 'FL', 'Miami', '55674', '524-965-8752', '789 Orange St', '08-09-2015', 9875 EXEC AddVendor 1000000018, 40000, 'Organic Dry Foods', 'USA', 'FL', 'Miami', '55674', '524-965-8752', '789 Orange St', '08-09-2015', 5486 EXEC AddVendor 1000000019, 50000, 'Organic Dry Foods', 'USA', 'FL', 'Miami', '55674', '524-965-8752', '789 Orange St', '08-09-2015', 5846 ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- --------- ------------------------------------------------------------------------------Part 4----- ----------------------------------------------------------------------------------------- ------- ---Copy and past this in fourth up to the bottom line. CREATE PROC AddItems (@itemUPC INT, @itemname VARCHAR(50), @itemprice MONEY, @aisle INT, @storeonhand INT) AS BEGIN INSERT INTO Items (item_UPC, item_name, item_price, aisle, store_on_hand) VALUES (@itemUPC, @itemname, @itemprice, @aisle, @storeonhand) END ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- ------- --------------------------------------------------------------------------Part 5--------- ----------------------------------------------------------------------------------------- ---------- ----Copy and past this in fifth up to the bottom line.----------------------------------- ----------------------------------------------------------------------------------------- ----------- EXEC AddItems 1000000001, 'Apples| 3 lb', '0.30', 1, 70; EXEC AddItems 1000000002, 'Oranges| 2 lb', '0.75', 1, 70; EXEC AddItems 1000000003, 'Watermelons', '1.00', 1, 70; EXEC AddItems 1000000004, 'Kiwis| per bag', '2.90', 1, 43; EXEC AddItems 1000000005, 'Plums| 2 lb', '0.40', 1, 70; EXEC AddItems 1000000006, 'Grapes| per bag', '2.30', 1, 20; EXEC AddItems 1000000007, 'Bananas| per bag', '2.70', 1, 40; EXEC AddItems 1000000008, 'Lettuce', '2.50', 2, 70; EXEC AddItems 1000000009, 'Potatoes| per bag', '2.00', 2, 40; EXEC AddItems 1000000010, 'Cabbage', '3.00', 2, 40; EXEC AddItems 1000000011, 'Steak 4 pack', '25.00', 3, 70; EXEC AddItems 1000000012, 'Pork 4 pack', '15.00', 3, 70; EXEC AddItems 1000000013, 'Chicken', '9.57', 3, 70; EXEC AddItems 1000000014, 'Ham', '8.00', 3, 70; EXEC AddItems 1000000015, 'Turkey', '25.95', 3, 70;
  • 4. EXEC AddItems 1000000016, 'Cereal', '3.00', 4, 30; EXEC AddItems 1000000017, 'Dried Oats', '2.50', 4, 70; EXEC AddItems 1000000018, 'Nuts| 2 lb', '1.36', 4, 1568; EXEC AddItems 1000000019, 'Cashews| 2 lb', '6.99', 4, 8524; ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- --------------- ----------------------------------------------------------------------------------------- --Part 6--------------------------------------------------------------------------------- -------------- ---------Copy and past this in sixth up to the bottom line.------------------------------ ----------------------------------------------------------------------------------------- ---------------- CREATE PROC AddOnlineOrders (@itemUPC INT, @onlprice MONEY, @onlcustid VARCHAR(50)) AS BEGIN INSERT INTO OnlineOrders (item_UPC, online_price, online_custid) VALUES (@itemUPC, @onlprice, @onlcustid) END ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- ---------------------------- --------------------------------------------------------------------------------Part 7--- ----------------------------------------------------------------------------------------- --------------------------- ----Copy and past this in seventh up to the bottom line.--------------------------------- ----------------------------------------------------------------------------------------- ------------- EXEC AddOnlineOrders 1000000011, 29.99, 'steak_lover'; EXEC AddOnlineOrders 1000000002, 0.75, 'j_aime_des_oranges'; EXEC AddOnlineOrders 1000000009, 2.00, 'picky_potato'; ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- ------------------- --------------------------------------------------------------------------------------- Part 8----------------------------------------------------------------------------------- ------------------------------- ----Copy and past this in eighth up to the bottom line.---------------------------------- ----------------------------------------------------------------------------------------- ------------ CREATE PROC AddOnlineCust (@onlcustid VARCHAR(50), @custname VARCHAR(50), @custaddress VARCHAR(50), @custcity VARCHAR(20), @custcountry VARCHAR(20), @custstate CHAR(2), @custzip VARCHAR(15), @custemail VARCHAR(50), @custphone VARCHAR(20), @orderdate DATE) AS BEGIN INSERT INTO OnlineCustomers (online_custid, cust_name, cust_address, cust_city, cust_country, cust_state, cust_zip, cust_email, cust_phone, order_date) VALUES (@onlcustid, @custname, @custaddress, @custcity, @custcountry, @custstate, @custzip, @custemail, @custphone, @orderdate) END ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- -------------------------------------
  • 5. -------------------------------------------------------------------------------------- Part 9----------------------------------------------------------------------------------- ----------------------------------- ----Copy and past this in ninth up to the bottom line.----------------------------------- ----------------------------------------------------------------------------------------- --------------- EXEC AddOnlineCust 'steak_lover', 'Christopher Steakous', '156 Steak Rd', 'Philadelphia', 'USA', 'PA', '19065', 'loverofsteak@steak.com', '215-584-9638', '01-01-2016' EXEC AddOnlineCust 'j_aime_des_oranges', 'Philipe Orange', '352 rue Beauvoir', 'Quebec', 'Canada', 'QC', 'H2A 6D3 ', 'philipe@rodgers.com', '658-521-9632', '01-01-2016' EXEC AddOnlineCust 'picky_potato', 'Bob Prank', '169 Prank Rd', 'New York City', 'USA', 'NY', '56821', 'bob@bob.com', '785-565-9274', '01-01-2016' ----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- -------------------- -------------------------------------------------------------------------------MISC Stored Procedures for analysis----------------------------------------------------------- ----------- --This stored procedures allows you to count how many orders a customer has placed in the system CREATE PROC NumOrderPerCust (@custname VARCHAR(50)) AS BEGIN SELECT OC.cust_name, COUNT(OO.online_custid) AS num_of_orders FROM OnlineCustomers AS OC FULL OUTER JOIN OnlineOrders AS OO ON OC.online_custid = OO.online_custid WHERE OC.cust_name LIKE '%' + @custname + '%' GROUP BY OC.cust_name END --This stored procedure allows you to see how many overall orders are in the system CREATE PROC OrdersInSystem AS SELECT OC.cust_name, COUNT(OO.online_custid) AS num_of_orders FROM OnlineCustomers AS OC FULL OUTER JOIN OnlineOrders AS OO ON OC.online_custid = OO.online_custid GROUP BY OC.cust_name