Question
i need small help to fix this , there is slight errors in this sql please help -- -------------------------------------------------------------------------------- -- Name: Student One -- Class:
i need small help to fix this , there is slight errors in this sql
please help
-- --------------------------------------------------------------------------------
-- Name: Student One
-- Class: SQL Example
-- Abstract: Example 1
-- --------------------------------------------------------------------------------
-- --------------------------------------------------------------------------------
-- Options
-- --------------------------------------------------------------------------------
USE dbSQL1 -- Get out of the master database
SET NOCOUNT ON; -- Report only errors
-- --------------------------------------------------------------------------------
-- Problem #1
-- --------------------------------------------------------------------------------
-- Drop Table Statements
IF OBJECT_ID ('TOrderProducts') IS NOT NULL DROP TABLE TOrderProducts
IF OBJECt_ID ('TOrders' ) IS NOT NULL DROP TABLE TOrders
IF OBJECt_ID ('TProducts' ) IS NOT NULL DROP TABLE TProducts
If OBJECT_ID ('TVendors' ) IS NOT NULL DROP TABLE TVENDORS
IF OBJECt_ID ('TCustomer' ) IS NOT NULL DROP TABLE TCustomer
-- --------------------------------------------------------------------------------
-- Step #1 : Create table
-- --------------------------------------------------------------------------------
CREATE TABLE TCustomer
(
intCustomerID INTEGER NOT NULL
,strFirstName VARCHAR(25) NOT NULL
,strLastName VARCHAR(25) NOT NULL
,strAddress VARCHAR(25) NOT NULL
,strCity VARCHAR(25) NOT NULL
,strState VARCHAR(25) NOT NULL
,strZip VARCHAR(25) NOT NULL
,strGender VARCHAR(25) NOT NULL
,dtmDateOfBirth DATETIME NOT NULL
,CONSTRAINT TCustomer_PK PRIMARY KEY ( intCustomerID )
)
CREATE TABLE TOrders
(
intOrdersID INTEGER NOT NULL
,intCustomerID INTEGER NOT NULL
, strOrderNumber VARCHAR(25) NOT NULl
, dtmOrderDate DATETIME NOT NULL
, strStatus VARCHAR(25) NOT NULL
,CONSTRAINT TOrders_PK PRIMARY KEY ( intOrdersID )
)
CREATE TABLE TProducts
(
intProductsID INTEGER NOT NULL
,intVendorsID INTEGER NOT NULL
,strName VARCHAR(25) NOT NULL
,intcostofproducts INTEGER NOT NULL
,intRetailCost INTEGER NOT NULL
,strProduceCategory VARCHAR(25) NOT NULL
,intInventory INTEGER NOT NULL
,CONSTRAINT TProducts_PK PRIMARY KEY ( intProductsID )
)
CREATE TABLE TOrderProducts
( intOrderProductID INTEGER NOT NULL
,intorderID INTEGER NOT NULL
,IntProductID INTEGER NOT NULL
,CONSTRAINT TOrderProducts_pk PRIMARY KEY (intOrderProductID)
)
CREATE TABLE TVendors
(
intVendorsID INTEGER NOT NULL
,strVendorsName VARCHAR(25) NOT NULL
,strAdress VARCHAR(25) NOT NULL
,strCity VARCHAR(25) NOT NULL
,strState VARCHAR(25) NOT NULL
,strZip VARCHAR(25) NOT NULL
,strcontactFirstName VARCHAR(25) NOT NULL
,strContactLastName VARCHAR(25) NOT NULL
,strContactPhoneNo VARCHAR(25) NOT NULL
,strContactEmail VARCHAR(25) NOT NULL
,CONSTRAINT TVendors_PK PRIMARY KEY ( intVendorsID )
)
-- --------------------------------------------------------------------------------
-- Step #3 : Create relationships. Foreign Keys
-- --------------------------------------------------------------------------------
-- Child Parent Column(s)
-- ----- ------ ---------
--1 TCustomer Torders intOrderID
--2 TVendors TProducts intProductID
--3 TOrders TOrderProducts intOrderProductID
--4 TProducts TOrderProducts intOrderProductID
--ALTER TABLE
--FOREIGN KEY (
---- 1
ALTER TABLE TCustomer ADD CONSTRAINT TCustomer_TOrders_FK1
FOREIGN KEY ( intOrderID ) REFERENCES TCustomer ( intOrderID )
-- 2
ALTER TABLE TVendors ADD CONSTRAINT TVendors_TProducts_FK
FOREIGN KEY (intProductID ) REFERENCES TVendors ( intProductID)
-- 3
ALTER TABLE TOrders ADD CONSTRAINT TOrders_TOrderProducts_FK1
FOREIGN KEY ( intOrderProductID ) REFERENCES TOrderProducts ( intOrderProductID )
-- 4
ALTER TABLE TProducts ADD CONSTRAINT TProducts_TOrderProducts_FK1
FOREIGN KEY ( intOrderProductID ) REFERENCES TOrderProducts ( intOrderProductID )
-- --------------------------------------------------------------------------------
-- Step #2 : Add Sample Data - INSERTS
-- --------------------------------------------------------------------------------
INSERT INTO TCustomer (intCustomerID, strFirstName, strLastName, strAddress, strCity ,strState ,strZip , strGender ,dtmDateOfBirth)
VALUES ( 1, 'Bishnu ' , 'pandey' , '123 Tolgate ct' , 'Chicago' , 'IL' ,'60626' , 'm' , '11/07/2005')
,( 2, 'Ram ' , 'sunwar' , '456 Colgate ct' , 'rockford' , 'Oh' ,'45014' , 'f' , '12/05/2006')
,( 3, 'Hari ' , 'Kour' , '789 Martha ct' , 'wheaton' , 'VA' ,'69023' , 'm' , '03/15/2009')
,( 4, 'Shyam ' , 'Oli' , '102 state st' , 'Claremont' , 'WA' ,'12522' , 'f' , '10/15/2010')
INSERT INTO TVendors ( intVendorsID, strVendorsName ,strAdress ,strCity ,strState ,strZip ,strcontactFirstName ,strContactLastName ,strContactPhoneNo ,strContactEmail)
VALUES (1, 'macys' , '902 springfeild pike' , 'Cincinnati' , 'OH' , '45231', 'John', 'James', '513-652-9853' , 'John@macys.com')
,(2, 'Krogers', '405 fairfeild rd' , 'Fairfeild' , 'OH' , '55231', 'Ram' , 'Lee' , '513-652-9853', ' Ram@kroger.com')
,(3, 'Walmart', '602 springgrove pike' , 'Cincinnati' , 'OH' , '65231', 'Bob' , 'Neils', '513-652-9853', 'Bob@Walmart.com')
,(4, 'Sams' , '702 Peachtree ct' , 'Cincinnati' , 'OH' , '25231', 'Dan' , 'King' , '513-652-9853', 'Dan@sams.com')
INSERT INTO TProducts (intproductsID,intVendorsID, strName ,intcostofproducts ,intRetailCost ,strProduceCategory ,intInventory)
VALUES (1 ,2, ' books ' , '50' , '20' , 'Yearly' , '5')
,(2 ,3, ' bags ' , '100' , '20' , 'Quertly', '4')
,(3 ,1, ' clothes' , '200' , '20' , 'Yearly' , '3')
,(4 ,2, ' beer' , '250' , '20' , 'SemiAnually', '2')
INSERT INTO TOrders (intOrdersID ,intCustomerID, strOrderNumber, dtmOrderDate, strStatus)
VALUES ( 1,2, '21 ' , '01/01/2018' , 'Open')
,( 2,3, '22 ' , '02/01/2018' , 'Close')
,( 3,2, '23 ' , '03/01/2018' , 'Close')
,( 4,1, '24 ' , '04/01/2018' , 'Open')
INSERT INTO TOrderProducts(intOrderProductID, intorderID ,IntProductID)
VALUES (1,1,1)
,(2,3,2)
,(3,2,1)
,(4,1,3)
,(5,1,2)
-- --------------------------------------------------------------------------------
-- Step #4 : Check data in all tables
-- --------------------------------------------------------------------------------
-- --------------------------------------------------------------------------------
-- Step #5 : Select all Instructor and Course info
-- --------------------------------------------------------------------------------
-- --------------------------------------------------------------------------------
-- Step #6 : Select all Instructor and Course info for a certain Instructor
-- --------------------------------------------------------------------------------
-- --------------------------------------------------------------------------------
-- Step #7 : Select all Student and Course info
-- --------------------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started