Question

SQL queries and procedures TABLE: Employees Business Rules: EmployeeID is defined as the primary key. Address...

SQL queries and procedures

TABLE: Employees

Business Rules:

EmployeeID is defined as the primary key.

Address has been denormalized to include City and State for performance reasons.

DeptNbr is a foreign key that references DeptNbr in the Department table Manager is a foreign key that references EmployeeID in the Employees table

Data Structure:

(EmployeeId, LastName, FirstName, Street, City, State, Zip, DateOfHire, DateOfBirth, JobTitle, Salary, DeptNbr(fk), Manager(fk))

TABLE: Department

Business Rules:

DeptNbr is defined as the primary key.

Data Structure:

(DeptNbr, DeptName, DeptFax, DeptPhone)

TABLE: Customer

Business Rules:

CustID is defined as the primary key.

Address has been denormalized to include City and State for performance reasons.

Data Structure:

(CustId , CustLastName, CustFirstName, Street, City, State, Zip, CreditLimit, CurrentBalance)

TABLE: Product

Business Rules:

ProductNbr is defined as the primary key.

Data Structure:

(ProductNbr, ProductName, ProductLocation, QtyOnHand,ReorderQty, Cost, MSRP)

TABLE: Calls

Business Rules:

CallID is defined as the primary key.

CustID is a foreign key that references CustID in the Customer table.

ProductNbr is a foreign key that references ProductNbr in the Product table

EmployeeID is a foreign key that references EmployeeID in the Employee table

Data Structure:

(CallID, Date, ProblemDescr, Resolution, CustID(fk), ProductNbr(fk), EmployeeID(fk))

TABLE: Sales

Business Rules:

SalesOrderNbr is defined as the primary key.

CustID is a foreign key that references CustID in the Customer table.

EmployeeID is a foreign key that references EmployeeID in the Employee table.

Data Structure:

(SalesOrderNbr, CustID(fk),EmployeeID(fk),Date)

TABLE: SaleProduct

Business Rules:

SalesOrderNbr + ProductNbr is defined as a composite primary key.

SalesOrderNbr is a foreign key that references SalesOrderNbr in the Sales table.

ProductNbr is a foreign key that references ProductNbr in the Product table.

Data Structure: (SalesOrderNbr(fk), ProductNbr(fk),Qty,UnitPrice)

REQUIRED QUERIES:

Create each of the following queries. After the query has been written and tested, create a stored procedure for the query. Name of query/stored procedure is given in ( ) at beginning of query.

1. (EmpList) For each employee, list the name (first and last), job title . Sort the employees in order by last name.

2. (CustomerCredit) List all customers who have a balance greater than their credit limit. For each customer, list customer ID, last name, and amount over credit limit (use an alias for this column)

3. (TopProduct) Using the Sale_Product table, list the Product Number of the best selling product. "Best selling" refers to the product that has the most total quantity sold.

4. (SaleData) For each Sale, list the sale number, sale date and customer last name. (Inner Join)

5. (DeptEmployees) For each department, list the department name, and the names of employees in that department. List ALL departments, even if the department does not have any employees. (Outer Join)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Create Procedure EmpList
AS
Select FirstName, Lastname, JobTitle  From Employees order By LastName;

2. Create Procedure CustomerCredit
as
Select CustID, CustLastName, CurrentBalance - CreditLimit as " Amount Over Credit Limit" from Customer
where currentbalance > creditlimit

3. Create Procedure TopProduct
as
Select ProductNbr from SaleProduct order by Qty desc

4. Create Procedure SaleData
as

Select SalesOrderNbr, Date, CustLastName from sale Inner Join customer on sale.custID=Customer.CustID

5. Create Procedure DeptEmployees
as
select d.DeptName, e.FirstName, e.LastName
from Department d join Employees e
on Department.DeptNbr(+) = Employees.DeptNbr

Add a comment
Know the answer?
Add Answer to:
SQL queries and procedures TABLE: Employees Business Rules: EmployeeID is defined as the primary key. Address...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write SQL Queries Given the following tables (7pts) Retrieve the names of employees and their project...

    Write SQL Queries Given the following tables (7pts) Retrieve the names of employees and their project name. If the employee never worked on a project, show the names only the name, not the project name. (7pts) Retrieve the names of employees who have worked on the same project at a different location. (7pts) Retrieve the names of employees who have worked on more than two different projects. (7pts) Retrieve the names of employees who manage more than two employees. CREATE...

  • NEED THE SQL QUERIES ASAP PLEASE(LIKE 1 HOUR) THE ONES WITH ID ARE PRIMARY KEYS OR...

    NEED THE SQL QUERIES ASAP PLEASE(LIKE 1 HOUR) THE ONES WITH ID ARE PRIMARY KEYS OR FOREIGN etc Customer [ CustID, LastName, FirstName, Address, City, State, Zip, Phone, Fax, Email] Product [ ProdID, Description, Color, Size, Pack] Sales [ TransID, CustID, ProdID, Price, Quantity, Amount] Write SQL statement to produce a list of unique products and their prices from the Sales table. Please ensure that the products do not repeat. Write an SQL statement to list ProdID and Description for...

  • WRITING POSTGRESQL QUERIES RELATIONS: CREATE TABLE Movies(    movieID INT,    year INT UNIQUE,    rating...

    WRITING POSTGRESQL QUERIES RELATIONS: CREATE TABLE Movies(    movieID INT,    year INT UNIQUE,    rating CHAR(1),    length INT,    totalEarned NUMERIC(7,2),    PRIMARY KEY(movieID) ); CREATE TABLE Theaters(    theaterID INT,    address VARCHAR(40) UNIQUE,    numSeats INT NOT NULL,    PRIMARY KEY(theaterID) ); CREATE TABLE TheaterSeats(    theaterID INT,    seatNum INT,    brokenSeat BOOLEAN NOT NULL,    PRIMARY KEY(theaterID, seatNum),    FOREIGN KEY(theaterID) REFERENCES Theaters ); CREATE TABLE Showings(    theaterID INT,    showingDate DATE,   ...

  • Please help I promise positive feedback Part IV. Formulate SQL queries that follow for the database...

    Please help I promise positive feedback Part IV. Formulate SQL queries that follow for the database with the following tables: CUSTOMER, PRODUCT, SALES, and ITEM-SOLD. Table: CUSTOMER Primary Key: Account-No Account-No Customer-Name Customer-City 1 A NYC 2 B NYC 3 C MIA Table: PRODUCT Primary Key: Item-No Item-No Price 1 $1.00 2 $2.00 3 $3.00 4 $4.00 Table: SALES Primary Key: Receipt-No Foreign Key: Account-No References CUSTOMER Receipt-No Account-No Sales-Person 1 1 S1 2 1 S1 3 2 S2 4...

  • Create a new database and execute the code below in SQL Server’s query window to create...

    Create a new database and execute the code below in SQL Server’s query window to create the database tables. CREATE TABLE PhysicianSpecialties (SpecialtyID integer, SpecialtyName varchar(50), CONSTRAINT PK_PhysicianSpecialties PRIMARY KEY (SpecialtyID)) go CREATE TABLE ZipCodes (ZipCode varchar(10), City varchar(50), State varchar(2), CONSTRAINT PK_ZipCodes PRIMARY KEY (ZipCode)) go CREATE TABLE PhysicianPractices (PracticeID integer, PracticeName varchar(50), Address_Line1 varchar(50), Address_Line2 varchar(50), ZipCode varchar(10), Phone varchar(14), Fax varchar(14), WebsiteURL varchar(50), CONSTRAINT PK_PhysicianPractices PRIMARY KEY (PracticeID), CONSTRAINT FK_PhysicianPractices_ZipCodes FOREIGN KEY (ZipCode) REFERENCES Zipcodes) go CREATE...

  • Given (Oracle) SQL Script " CREATE TABLE Members(    MemberID NUMBER(4) NOT NULL PRIMARY KEY,   ...

    Given (Oracle) SQL Script " CREATE TABLE Members(    MemberID NUMBER(4) NOT NULL PRIMARY KEY,    MFirst VARCHAR(25) NOT NULL,    MLast VARCHAR(25) NOT NULL,    Street VARCHAR(64) NOT NULL,    City VARCHAR(25) NOT NULL,    State VARCHAR(2) NOT NULL,    ZipCode NUMBER(5) NOT NULL,    CreditLimit NUMBER(7,2) NOT NULL,    Gender VARCHAR(1) NOT NULL CHECK (Gender IN('F','M')) ); CREATE TABLE Employees(    EmployeeID NUMBER(3) NOT NULL PRIMARY KEY,    EFirst VARCHAR(25) NOT NULL,    ELast VARCHAR(25) NOT NULL,   ...

  • SQL Queries – in this assignment you will be asked to create several SQL queries relating...

    SQL Queries – in this assignment you will be asked to create several SQL queries relating to the Sakila database that we installed in class. You may freely use DBeaver to create these queries, but I will expect your solution to show me the SQL code to answer or complete the tasks below. Write a query that produces the last name, first name, address, district, and phone number for every customer in the customer table. (You don’t need to include...

  • (Using Oracle SQL) How do I find the primary key of this table? And then how...

    (Using Oracle SQL) How do I find the primary key of this table? And then how do I consequently drop the primary key from the table? Edit: I was already give this code and it did not work select constraint_name,constraint_type from user_constraint where table_name='CUSTOMER'; Q7 (10 Points) Use ONE SQL statement to find out the name of the primary key constraint defined on Customer table. (Your SQL should return something like SYS_C0021715, numbers on your account may differ.) Then use...

  • I have already turned in my HW, I need some understanding of the below SQL queries....

    I have already turned in my HW, I need some understanding of the below SQL queries. 1. Find the number of employees in each department. 2. List the names of departments that have more than 5 employees working there. 3. Retrieve the lowest and highest salary in each department. Output the department name in alphabetical order. Consider the following relational schema. An employee can work in more than on department; also, the percentTime field of the Works relations shows the...

  • Create the database and tables for the database. Show all SQL statements. Include primary and foreign...

    Create the database and tables for the database. Show all SQL statements. Include primary and foreign keys. Insert data into each table. Show select statements and display the output of each table. Note:Student’s name must be inserted into table as part of the data! Perform the SQL below: Query one table and use WHERE to filter the results. The SELECT clause should have a column list, not an asterisk (*). State the purpose of the query; show the query and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT