Question

In: Computer Science

Here is listing of the tables for the database for this assignment. SELLERS(SellerNum, SellerLastName, SellerFirstName, SellerStreet,...

Here is listing of the tables for the database for this assignment.

SELLERS(SellerNum, SellerLastName, SellerFirstName, SellerStreet, SellerCity, SellerState, SellerZip, CRate)

BUYERS(BuyerNum, BuyerLastName, BuyerFirstName, BuyerStreet, BuyerCity, BuyerState, BuyerZip, BonusLevel, SellerNum)

PRODUCTS(ProductNum, Description, NumberInStock)

STATEMENT(StatementNum, StatementDate, BuyerNum)

STATEMENTLINE(StatementNum, ProductNum, Quantity, ItemPrice)

Using the above database’s tables, respond to the following questions:

  1. Write SQL CREATE TABLE statements for each of the above tables. Be sure to include the Primary and Foreign keys.

Note: The id numbers for each table should be a numeric (integer) value, the commission rate (Crate) and the ItemPer (individual quoted price per item) should be numeric with 2 decimal places, and the quantity (quantity of the products ordered) and NumberInStock (number of items in stock) should be numeric (integer) values. Additionally, the states should use the common 2 character state abbreviation and the statement date should be a date value. All other values are character values.

  1. Write SQL statements to insert onecomplete row of data into each table. You make up the values that go in the rows.
  2. Write SQL statements to list all columns of each table -- one statement per table.
  3. Write a SQL statement to list all of the sellers (first and last names and commission rates) that have commission rates of 4.25% (as a decimal value) or higher
  4. Write a SQL statement to list all of the buyers (first and last names) that have a bonus level of “Green”.
  5. Write a SQL statement to list the all of the Arkansas buyers’ first and last names in alphabetical order.
  6. One of the sellers has a last name of “Lee”, another has the last name of “Caswell”. Write a SQL statement to list all of the buyers (first and last names) that have been assigned to them.
  7. One of the buyers has the last name of “Gadea”. Write a SQL statement to list the descriptions of all of the items that she purchased.

Solutions

Expert Solution

Question1 : Write SQL CREATE TABLE statements for each of the above tables. Be sure to include the Primary and Foreign keys.

Answer :

  • SELLERS(SellerNum, SellerLastName, SellerFirstName, SellerStreet, SellerCity, SellerState, SellerZip, CRate)

CREATE TABLE SELLER (

SellerNum int NOT NULL,

SellerLastName varchar(100),

SellerFirstName varchar(100),

SellerStreet varchar(255),

SellerCity varchar(255),

SellerState varchar(255),

SellerZip int,

CRate varchar(255)

PRIMERY KEY(SellerNum)

);

  • BUYERS(BuyerNum, BuyerLastName, BuyerFirstName, BuyerStreet, BuyerCity, BuyerState, BuyerZip, BonusLevel, SellerNum)

CREATE TABLE BUYERS(

BuyerNum int NOT NULL,

BuyerLastName varchar(255),

BuyerFirstName varchar(255),

BuyerStreet varchar(255),

BuyerCity varchar(255),

BuyerState varchar(255),

BuyerZip varchar(255),

BonusLevel varchar(255),

SellerNum varchar(255),

PRIMARY KEY(BuyerNum),

FOREIGN KEY(SellerNum)

);

  • PRODUCTS(ProductNum, Description, NumberInStock)

CREATE TABLE PRODUCTS (

ProductNum int NOT NULL,

Description varchar(255),

NumberInStock int,

PRIMARY KEY(ProductNum)

);

  • STATEMENT(StatementNum, StatementDate, BuyerNum)

CREATE TABLE STATEMENT(

StatementNum int NOT NULL,

StatementDate date,

BuyerNum int ,

PRIMARY KEY(StatementNum),

FOREIGN KEY(BuyerNum)

);

  • STATEMENTLINE(StatementNum, ProductNum, Quantity, ItemPrice)

CREATE TABLE STATEMENTLINE(

StatementNum int NOT NULL,

ProductNum int,

Quantity int,

ItemPrice float,

PRIMARY KEY(StatementNum),

FOREIGN KEY(ProductNum)

);

Question 2 : Write SQL statements to insert onecomplete row of data into each table.

Answer :

INSERT INTO SELLER

(SellerNum, SellerLastName, SellerFirstName, SellerStreet, SellerCity, SellerState, SellerZip, CRate)

VALUES

(1,'SINGH','RANVEER','STREET NO-3','LUDHIANA','PUNJAB','140141','1440');

INSERT INTO BUYERS(BuyerNum, BuyerLastName, BuyerFirstName, BuyerStreet, BuyerCity, BuyerState, BuyerZip, BonusLevel, SellerNum) VALUES (1,'DEEP','AMAN','SHIVAJI STREET','RAJPURA','PUNJAB','140401' , 'GREEN',1);

INSERT INTO PRODUCTS(ProductNum, Description, NumberInStock) VALUES (1,'Skin Glowing Creame',87);

INSERT INTO STATEMENT(StatementNum, StatementDate, BuyerNum) VALUES (1,2020/09/26,1);

INSERT INTO STATEMENTLINE(StatementNum, ProductNum, Quantity, ItemPrice) VALUES (1,1,10,49);

Question 3 :  Write SQL statements to list all columns of each table.

Answer :

SELECT * FROM SELLER;

SELECT * FROM BUYERS;

SELECT * FROM PRODUCTS;

SELECT * FROM STATEMENT;

SELECT * FROM STATEMENTLINE;

Question 4 : Write a SQL statement to list all of the sellers (first and last names and commission rates) that have commission rates of 4.25% (as a decimal value) or higher

Answer :

SELECT * FROM SELLERS WHERE CRate>=4.25;

Question 5 :Write a SQL statement to list all of the buyers (first and last names) that have a bonus level of “Green”

Answer :

SELECT * FROM BUYERS WHERE BonusLevel = 'GREEN';

Question 6: Write a SQL statement to list the all of the Arkansas buyers’ first and last names in alphabetical order.

Answer :

SELECT BuyerLastName, BuyerFirstName FROM BUYERS ORDER BY BuyerFirstName

Question 7: One of the sellers has a last name of “Lee”, another has the last name of “Caswell”. Write a SQL statement to list all of the buyers (first and last names) that have been assigned to them.

Answer:

DECLARE @Temp1 AS int, @Temp2 AS int;

SET @Temp1 = (Select SellerNum From SELLERS WHERE  SellerLastName = 'Lee';

SET @Temp2 = (Select SellerNum From SELLERS WHERE  SellerLastName = 'Caswell';

SELECT BuyerLastName, BuyerFirstName FROM BUYERS WHERE SellerNum = @Temp1;

SELECT BuyerLastName, BuyerFirstName FROM BUYERS WHERE SellerNum = @Temp2;

Question 8 : One of the buyers has the last name of “Gadea”. Write a SQL statement to list the descriptions of all of the items that she purchased.

Answer:

DECLARE @ID AS INT;

SET @ID = (SELECT BuyerNum FROM BUYERS WHERE BuyerLastName = 'Gadea');

DECLARE @ID2 AS INT;

SET @ID = (SELECT StatementNum FROM STATEMENT WHERE BUYERNUM = ID1);

I am not clearly sure about the last question so i am very sorry for this . Please rate

Thankyou


Related Solutions

Database Design Design a database and show the relationship between each tables. I need multiple tables....
Database Design Design a database and show the relationship between each tables. I need multiple tables. *Must meet the requirements for Third Normal Form. These are the information for employee DB. Employee Number, First Name, Last Name, Date of birth, Address, city, state, zip, department, job title, supervisor, health insurance number, health insurance provider, dental insurance number, dental insurance provider, spouse/partner, children, children's ages.
Use MYSQL to create the set of database tables of the relational database model and complete...
Use MYSQL to create the set of database tables of the relational database model and complete the associated queries given. Procedure: 1) Write all the SQL statements, necessary to create all tables and relationships, with Primary & Foreign keys. 2) Execute each statement in the correct order to create the relational database in MYSQL. 3)Insert some data into each table. 4) Use all your SQL create and Insert statements (from MS Word) to execute in the MYSQL WorkBench 5) Write...
The following tables form part of a database (Flights Database) held in a relational DBMS: employee...
The following tables form part of a database (Flights Database) held in a relational DBMS: employee (empNo, empName, empSalary, empPosition) aircraft (aircraftNo, acName, acModel, acFlyingRange) flight (flightNo, aircraftNo, fromAirport, toAirport, flightDistance, departTime, arriveTime) certified (empNo, aircraftNo) Where:  employee contains details of all employees (pilots and non-pilots) and empNo is the primary key;  aircraft contains details of aircraft and C is the primary key.  flight contains details of flights and (flightNo, aircraftNo) form the primary key.  certified...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient,...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient, fullName, biologicalMother, birthdate, address) doctor(idDr, fullName, specialization, consulRates) inpatient(idPatient, entryTime, outTime, idDr, idRoom). Please make entryTime as column that is going to be filled automatically when care record is being add room(idRoom, roomName, cost) fill the data above to each table Create sql query and relational algebra expressions for the query Please give me detailed answer so I could learn from it. Thank you...
1. Discuss the elements of a database system. Like The database schema Schema objects Indexes Tables...
1. Discuss the elements of a database system. Like The database schema Schema objects Indexes Tables Fields and columns Records and rows Keys Relationships Data types 2. Discuss the key components of a database management system architecture and how they collaborate. 3. Discuss why a database management system needs a good query optimizer.
We use the WMCRM database and here is the summary of the database schema (where schema...
We use the WMCRM database and here is the summary of the database schema (where schema is used in its meaning of a summary of the database structure): VEHICLE (InventoryID, Model, VIN) SALESPERSON (NickName, LastName, FirstName, HireDate, WageRate, CommissionRate, OfficePhone, EmailAddress, InventoryID) CUSTOMER (CustomerID, LastName, FirstName, Address, City, State, ZIP, EmailAddress, NickName) PHONE_NUMBER (CustomerID, PhoneNumber, PhoneType) CONTACT(ContactID, CustomerID,ContactDate,ContactType,Remarks) Where InventoryID in SALESPERSON must exist in InventoryID in VEHICLE NickName in CUSTOMER must exist in NickName in SALESPERSON CustomerID in PHONE_NUMBER...
Assignment 3 Note: Tables referred in this assignment are same as that of Assignment 2. 1....
Assignment 3 Note: Tables referred in this assignment are same as that of Assignment 2. 1. For each table, append your student id along with the table name. For e.g. employee_student id (employee_T16363737) 2. Format for questions: a. Question: b. SQL statement solution c. Screenshot for correct input d. Screenshot for violation (if any) Q1) Check the structure of tables. Q2) Check the constraint name for applied constraints? Q3) Drop the unique constraint on ENAME Q4) Drop the Foreign Key...
Consider an ONLINE_AUCTION database system in which members (buyers and sellers) participate in the sale of...
Consider an ONLINE_AUCTION database system in which members (buyers and sellers) participate in the sale of items. Design an ER/EER diagram for this ONLINE_AUCTION database. The data requirements for this system are summarized as follows: • The online site has members, each of whom is identified by a unique member number and is described by an e-mail address, name, password, home address, and phone number. • A member may be a buyer or a seller. A buyer has a shipping...
mySQL database question.. I have a database that has the following tables: User (Id, Name, Gender)...
mySQL database question.. I have a database that has the following tables: User (Id, Name, Gender) Primary key = Id Friends (Id1, Id2, Startdate) Primary key = (Id1, Id2) Foreign keys are also Id1, Id2 pointing to User(Id) Comments (CommentId, Poster, Recipient, Text, PostDate) Primary key = (CommentId) Foreign Keys are Poster, Recipient pointing to User(Id) I need to answer the following queries: 5. List Users who have posted comments to all female users 6. List User(s) who have received...
RSQLite (using R studio) 1. Make you have imported the database tables into your database (I've...
RSQLite (using R studio) 1. Make you have imported the database tables into your database (I've copied and pasted these at the bottom). Write and submit the following RSQLite queries. 2. Retrieve the names of all employees. 3. Retrieve the names of all distinct employee names. 4. Retrieve the names of all employees whose name begins with the letter ‘B’. 5. Retrieve the names and NI numbers (NI_NO) of all employees. 6. Retrieve details of employees who are over 31...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT