0% found this document useful (0 votes)
8 views

SQL_QUIRIES

The document outlines a lab assignment focused on creating, populating, and querying a relational database schema for a COMPANY database using SQL. It includes tasks such as creating tables, inserting data, generating views for department headcounts, and updating employee information. Additionally, it requires writing specific SQL queries to retrieve data based on various conditions and documenting the work with screenshots.

Uploaded by

rojamani ganta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL_QUIRIES

The document outlines a lab assignment focused on creating, populating, and querying a relational database schema for a COMPANY database using SQL. It includes tasks such as creating tables, inserting data, generating views for department headcounts, and updating employee information. Additionally, it requires writing specific SQL queries to retrieve data based on various conditions and documenting the work with screenshots.

Uploaded by

rojamani ganta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab Assignment 0

SS Chung

1. Creating a Relational Database Schema from ER Diagram, Populating


the Database and Querying over the database with SQL

1. Creating the COMPANY database schema using SQL (DDL) statements.


The COMPANY database schema is depicted in Figure 5.7 in the back (in Page 75 in Text Book)
from ER Diagram in Figure 7-2 in Page 204 in Textbook). Core data for this database is shown in
Figure 3.6 in the back (in page 72 in Textbook).
Write the corresponding SQL commands (DDL) to create all 6 Tables as shown in Figure 5.7.

The typical SQL commands (DDL) for this lab are as follow:

Drop table Employee;


Create table Employee ( ....);
ALTER TABLE EMPLOYEE ADD COLUMN…
ALTER TABLE EMPLOYEE ADD CONSTRAINT…
ALTER TABLE EMPLOYEE DROP COLUMN…;
ALTER TABLE EMPLOYEE DROP CONSTRAINT…;
ALTER TABLE EMPLOYEE ALTER COLUMN…;
Select * From Employee;

2. Populating the COMPANY database using SQL (DML) statements.

The typical SQL commands (DML) to populate a table and show the rows inserted into the table
for this task are like the following example.

INSERT INTO EMPLOYEE VALUES('John','B','Smith','123456789','9-Jan-55','731


Fondren, Houston, TX','M',30000,'987654321',5);

Select * From Employee;

Show your SQL statements and the result in a Word document. Add screenshots showing your
SQLs and the results to show the content of each table after populating it.

3. Write SQL as follow:

3-1) Write SQL using a view named VDept_Headcount that reports headcount for each
department. The report includes 3 columns as follow:
Dept_Name, Dept_Number, No_Emp.
Include all the departments.

3-2)
1) Add yourself to the database (Employee, Dependent, Works_On). Enter some
assignments, and family members.
2) Change your view to add one more info - Salary_Budget as total salary for each department.
Include all the departments. Your report lists 4 Columns as follow:
Dept_Name, Dept_Number, No_Emp, Salary_Budget

3) Run the same query that you wrote in 3-1) to report the updated info after changes in the
database.

Show your SQL statements and the result in a Word document. Add screenshots showing your
SQLs and the results to show your report is updated before and after the changes in the
database.

4. Update the following new changes into the database:

1) Joyce English with Ssn = 453453453 got married with John.


2) Jenifer Wallace with Ssn = 987654321 just had a new daughter named Erica.
3) Jenifer Wallace with Ssn = 987654321 is just assigned to a new project number ‘10’ to work
on.

Add these new entries into Dependent, Works_On tables in your database then Select * from
Dependent and Select * from Works_On to show the updated table contents.

5. Write SQL Select statements to retrieve data in the followings:

Q1:
Make a list of all project numbers that Research department employees are working on,
either as a worker or as a manager of the department that controls the projects.

Q2:
Get SSN and the last name of married female employees who work on three or more
projects

Q3. Write SQL using View instead of Subquery (the part to find the employees who are
working on three more projects) to express the same query Q2.

Q4:
Get the last name of married employees who only have daughters.

(Hint: Indentify connections between the following three sets.

Married : From Dependent table with relationship = ‘spouse’;


Girls : From Dependent table with relationship = ‘daughter’;
Boys : From Dependent table with relationship relationship = ‘son’;
6. Document your work.
For each query, add a screenshot showing your SQL and the results together.

1. Your query and the result of your query for each question
2. Make a screenshot of each query and its result returned in one window to show
your query successfully returns the correct result.
3. Add comments, if needed, explaining the meaning of each component included
in the report.
4. Turn in a Printout of your report in Class for grading
5. Submit your lab report files on Blackboard for a timestamp
Figure 2. COMPANY SCHEMA - ER Diagram

Figure 3. Symbols of ER diagrams


COMPANY DATABASE

EMPLOYEE
FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY SUPERSSN DNO
John B Smith 123456789 09-Jan-55 731 Fondren, Houston, TX M 30000 987654321 5
Franklin T Wong 333445555 08-Dec-45 638 Voss, Houston, TX M 40000 888665555 5
Joyce A English 453453453 31-Jul-62 5631 Rice, Houston, TX F 25000 333445555 5
Ramesh K Narayan 666884444 15-Sep-52 975 Fire Oak, Humble, TX M 38000 333445555 5
James E Borg 888665555 10-Nov-27 450 Stone, Houston, TX M 55000 1
Jennifer S Wallace 987654321 20-Jun-31 291 Berry, Bellaire, TX F 43000 888665555 4
Ahmad V Jabbar 987987987 29-Mar-59 980 Dallas, Houston, TX M 25000 987654321 4
Alicia J Zelaya 999887777 19-Jul-58 3321 Castle, SPring, TX F 25000 987654321 4

DEPARTMENT
DNAME DNUMBER MGRSSN MGRSTARTDATE
Headquarters 1 888665555 19-Jun-71
Administration 4 987654321 01-Jan-85
Research 5 333445555 22-May-78
Automation 7 123456789 06-Oct-05

DEPENDENT
ESSN DEPENDENT_NAME SEX BDATE RELATIONSHIP
123456789 Alice F 31-Dec-78 Daughter
123456789 Elizabeth F 05-May-57 Spouse
123456789 Michael M 01-Jan-78 Son
333445555 Alice F 05-Apr-76 Daughter
333445555 Joy F 03-May-48 Spouse
333445555 Theodore M 25-Oct-73 Son
987654321 Abner M 29-Feb-32 Spouse

DEPT_LOCATIONS
DNUMBER DLOCATION
1 Houston
4 Stafford
5 Bellaire
5 Sugarland
5 Houston

PROJECT
PNAME PNUMBER PLOCATION DNUM
ProductX 1 Bellaire 5
ProductY 2 Sugarland 5
ProductZ 3 Houston 5
Computerization 10 Stafford 4
Reorganization 20 Houston 1
Newbenefits 30 Stafford 4

WORKS_ON
ESSN PNO Hours
123456789 1 32.5
123456789 2 7.5
333445555 2 10
333445555 3 10
333445555 10 10
333445555 20 10
453453453 1 20
453453453 2 20
666884444 3 40
888665555 20
987654321 20 15
987654321 30 20
987987987 10 35
987987987 30 5
999887777 10 10
999887777 30 30

You might also like