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.
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...
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...
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...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based on your entities defining The attributes within each table The primary and foreign keys within each table *****Show your database tables, tables attributes, primary and foreign keys***** Do not forget to check the lesson slides and videos that show you how to convert an ER/EER into a database schema, and how to create a database and tables using MS SQL Server.
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the...
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the tables as either entity or relationship The first step in building an E-R model is to identify the entities. Having identified the entities, the next step is to identify all the relationships that exist between these entities. Using the content of the relational database above: b) Using the relations in the relational database, explain how one can transform relationship in E-R model into a...
'driver', 'car', 'accident' and 'report' are names of some tables in the insurance database system. These...
'driver', 'car', 'accident' and 'report' are names of some tables in the insurance database system. These tables were created by executing the following SQL creation statements. CREATE TABLE driver( driverID INT NOT NULL PRIMARY KEY, name VARCHAR(30) NOT NULL, cityAddress VARCHAR(25) ); CREATE TABLE car( plateID INT NOT NULL PRIMARY KEY, model VARCHAR(20) NOT NULL, year YEAR(4) NOT NULL ); CREATE TABLE accident( reportNumber INT NOT NULL PRIMARY KEY, date Date NOT NULL, location VARCHAR(20) NOT NULL ); CREATE TABLE...
Question 2. The following tables provide some example data that will be kept in the database....
Question 2. The following tables provide some example data that will be kept in the database. Write the INSERT commands necessary to place the following data in the tables that were created in Question 1. Alternatively provide the text files (copy and pasted into your final report) and the open/insert from file commands.. Table: actor act_id | act_fname | act_lname | act_gender 101 | James | Stewart | M 102 | Deborah | Kerr | F 103 | Peter |...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT