This document contains the lab assignment details submitted by Sarthak Goyal for the Database Management lab. The assignment includes creating tables, adding constraints to tables, inserting data into tables and performing various operations like aggregation, filtering and grouping on the tables. Various SQL queries are written to select, alter, describe and insert data from the tables.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
38 views20 pages
21bce0968 VL2023240100969 Ast02
This document contains the lab assignment details submitted by Sarthak Goyal for the Database Management lab. The assignment includes creating tables, adding constraints to tables, inserting data into tables and performing various operations like aggregation, filtering and grouping on the tables. Various SQL queries are written to select, alter, describe and insert data from the tables.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20
Lab Assignment-2
DATABASE MANAGEMENT LAB
School Of Computer Science and Engineering
Submitted by:- Sarthak Goyal(21BCE0968)
Submitted to:- Govinda K
As we are using exercise 1 code in this so its code create table employee (first_name VARCHAR(15), mid_name CHAR(2), last_name VARCHAR(15), ssn_number CHAR(9), birthday DATE, address VARCHAR(50), sex CHAR(1), salary NUMBER(7), supervisior_ssn CHAR(9), department_number NUMBER(5));
ALTER TABLE employee modify first_name varchar(15) not null ;
desc employee; ALTER TABLE employee modify last_name varchar(15) not null ; desc employee; ALTER TABLE employee ADD CONSTRAINT pk_ssn PRIMARY KEY (ssn_number); desc employee; ALTER TABLE employee ADD CONSTRAINT check_sex CHECK (sex IN ('M', 'F', 'm', 'f')); desc employee; ALTER TABLE employee ALTER COLUMN salary SET DEFAULT 800; desc employee; ALTER TABLE employee ADD CONSTRAINT fk_employee_supervisor FOREIGN KEY (supervisior_ssn) REFERENCES employee (ssn_number) ON DELETE SET NULL; desc employee; ALTER TABLE employee ADD CONSTRAINT fk_e_department FOREIGN KEY (department_number) REFERENCES department (department_number) ON DELETE CASCADE; ALTER TABLE department modify departname_name varchar(15) not null ; ALTER TABLE department ADD CONSTRAINT pk_n PRIMARY KEY (department_number); ALTER TABLE department ADD CONSTRAINT fk_department_employee FOREIGN KEY (supervisior_ssn) REFERENCES employee (ssn_number) ON DELETE SET NULL; insert into employee values( 'Doug','E','Gilbert',554433221,'09-JUN-60','11 S 59 E, Salt Lake City, UT','M',80000,NULL,3); insert into employee values( 'Joyce','','PAN',543216789,'07-FEB-78','35 S 18 E, SaltLake City, UT','F',70000,NULL,2); insert into employee values( 'Frankin','T','Wong',333445555,'08-DEC-45','638 Voss,Houston, TX','M',40000,554433221,5); insert into employee values( 'Jennifer','S','Wallace ',987654321,'20-JUN- 31','291 Berry,Bellaire, TX ','F',43000,554433221,4); insert into employee values( 'John','B','Smith',123456789,'09-JAN-55','731 Fondren,Houston, TX','M',30000,333445555,5); insert into employee values( 'Ramesh','K','Narayan',666884444,'15-SEP- 52','975 Fire Oak,Humble, TX','M',38000,333445555,5); insert into employee values( 'Joyce','A','English',453453453,'31-JUL-62','5631 Rice,Houston, TX','F',25000,333445555,5); insert into employee values( 'James','E','Borg',888665555,'10-NOV-27','450 Stone,Houston, TX','M',55000,543216789,1); insert into employee values( 'Alicia','J','Zelaya',999887777,'19-JUL-58','3321 Castle,Spring, TX X','F',25000,987654321,4); insert into employee values( 'Ahmad','V','Jabbar',987987987,'29-MAR- 59','980 Dallas,Houston, TX ','M',25000,987654321,4); Exercise: III Operators and Functions Aim: To understand different operators and types of function in SQL Execute the following queries based on the schema specified in exercise 1
1. Find the employee names having salary greater than Rs.25000.
2. Find the employee names whose salary lies in the range between 30000 and 70000. 3. Find the employees who have no supervisor. 4. Display the bdate of all employee s in the format ‘DDthMonthYYYY’. 5. Display the employee names whose bdate is on or before 1978. 6. Display the employee names having ‘salt lake’ in their address. 7. Display the department name that starts with ’M’. 8. Display the department names’ that ends with ‘E’. 9. Display the names of all the employees having supervisor with any of the following SSN 554433221, 333445555. 10. Display all the department names in upper case and lower case. 11. Display the first four characters and last four of the department names using ltrim and rtrim. 12. Display the substring of the Address (starting from 5th position to 11 th position) of all employees. 13. Display the Mgrstartdate on adding three months to it. 14. Display the age of all the employees rounded to two digits. 15. Find the last day and next day of the month in which each manager has joined. Solution:-
1.Find the employee names having salary greater than
Rs.25000.
2.Find the employee names whose salary lies in the range
between 30000 and 70000.
3. Find the employees who have no supervisor.
4. Display the bdate of all employee s in the format ‘DDthMonthYYYY’.
5. Display the employee names whose bdate is on or before
1978.
6. Display the employee names having ‘salt lake’ in their
address. 7. Display the department name that starts with ’M’.
8. Display the department names’ that ends with ‘E’
9. Display the names of all the employees having supervisor
with any of the following SSN 554433221, 333445555.
10. Display all the department names in upper case and
lower case. 11.Display the first four characters and last four of the department names using ltrim and rtrim.
12. Display the substring of the Address (starting from 5th
position to 11 th position) of all employees. 13. Display the Mgrstartdate on adding three months to it.
14. Display the age of all the employees rounded to two
digits. 15. Find the last day and next day of the month in which each manager has joined Exercise: IV Group Functions 1. How many different departments are there in the ‘employee’ table 2. For each department display the minimum and maximum employee salaries 3. Print the average annual salary. 4. Count the number of employees over 30 age. 5. Print the Department name and average salary of each department. 6. Display the department name which contains more than 30 employees. 7. Calculate the average salary of employees by department and age 8. Count separately the number of employees in the finance and research department. 9. List out the employees based on their seniority. 10. List out the employees who works in ‘manufacture’ department group by first name 1. How many different departments are there in the ‘employee’ table
2. For each department display the minimum and maximum
employee salaries
3. Print the average annual salary.
4. Count the number of employees over 30 age.
5. Print the Department name and average salary of each
department.
6. Display the department name which contains more than
30 employees. 7. Calculate the average salary of employees by department and age
8. Count separately the number of employees in the finance
and research department. For Finance
For Research 9. List out the employees based on their seniority.
10. List out the employees who works in ‘manufacture’