Professional Documents
Culture Documents
Keshav 03161188819 Ism Lab File Final
Keshav 03161188819 Ism Lab File Final
LAB FILE
MySQL is an important component of an open-source enterprise stack called LAMP. LAMP is a web development platform
that uses Linux as the operating system, Apache as the web server, MySQL as the relational database management system
and PHP as the object-oriented scripting language.
(Sometimes Perl or Python is used instead of PHP.)
MySQL is based on a client-server model. The core of MySQL is MySQL server, which handles all of the database
instructions (or commands). MySQL server is available as a separate program for use in a client-server networked
environment and as a library that can be embedded (or linked) into separate applications.
MySQL operates along with several utility programs which support the administration of MySQL databases. Commands are
sent to MySQL Server via the MySQL client, which is installed on a computer.
MySQL enables data to be stored and accessed across multiple storage engines, including Inno DB, CSV, and NDB.
MySQL is also capable of replicating data and partitioning tables for better performance and durability. MySQL users aren't
required to learn new commands; they can access their data using standard SQL commands.
MySQL is written in C and C++ and accessible and available across over 20 platforms, including Mac, Windows, Linux and
Unix. The RDBMS supports large databases with millions records and supports many data types including signed or
unsigned integers 1, 2, 3, 4, and 8 bytes long; FLOAT; DOUBLE; CHAR; VARCHAR; BINARY; VARBINARY; TEXT;
BLOB; DATE; TIME; DATETIME; TIMESTAMP; YEAR.
DECLARATION
I, Keshav Singh Gehlawat hereby declare that the present project report is submitted in partial fulfillment of my B.com
(Hons.) degree. The work was carried out with sincerity and complete dedication. All the assignments done are completed
by me only and has not been copied from anywhere else.
"I have taken efforts in this project. However, it would not have been possible without the kind support and help of many
individuals. I would like to extend my sincere thanks to all of them.
I am highly indebted to Mr. Praveen Kumar Singh, Assistant Professor, Department of Commerce for his guidance and
constant supervision as well as for providing necessary information regarding the project & also for his support in
completing the project.
I would also like to express my gratitude towards my parents & Dr. Manju Gupta, HOD, Department of Commerce
for their kind co-operation and encouragement which helped me in completion of this project.
My thanks and appreciations also go to my colleagues in developing the project and people who have willingly helped me
out with their abilities.
INDEX
12 Assign.12 60
13 Assign.13 Aggregate functions in SQL 68
14 Assign.14 Order by, group by and having clause 75
15 Assign.15 nested queries 81
16 Assign.16 JOIN SQL STATEMENT (INNER JOIN) 86
17 Assign.17 92
18 Assign.18 (OUTER JOIN) 95
19 Assign.19 (CROSS JOIN & SELF JOIN) 100
20 Assign.20 104
21 Assign.21 108
22 Assign.22 117
23 Assign.23 (E-R DIAGRAM) 121
24 Assign.24 124
25 Assign.25 (E-R DIAGRAM) 129
26 Assign.26 133
27 Assign.27 139
28 Assign.28 144
29 Assign.29 148
30 Assign.30( E-R DIAGRAM) 152
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Course/ Subject Code: BCOM307 Subject Title: Information System Management Lab
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
1 CO1
Create a table called “Persons” that contains five columns:
a) PersonID INT
b) FirstName Char (20)
c) LastName Char (20)
d) Address Varchar(25)
e) City char(10)
2 Insert any 5 values in the table “Persons”
3 View All records of the table “Persons”
1
ASSIGNMENT – 1
SQL CREATE TABLE COMMAND
Q1. Create a table named “Persons” with the following columns – person id, first name, last
name, address, city.
Syntax:
Create table table_name(
Column 1 data type,
Column 2 data type,
Column 3 data type);
Syntax:
INSERT INTO table_name (column1, column2, column3,….) VALUES (value1,
value2, value3,….);
Q3. To view all records from the table name persons
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question No.
No.
1 Create a table named Client_Master with the following columns: a. CO1,CO4
Client_No.
b. Name
c. Address
d. City
e. Pincode
f. State
g. Baldue
2 Insert any 5 rows in the above columns
Client_no
Name
Address
City
Pincode
State
Baldue
Q4. To display the details of all clients who belong to New Delhi
Q5. To display the names of the clients who belong to Haryana.
Q6. To display the client number and name whose balance due is greater than 5000.
Q7. To display the client number, city and pin code who belongs to New Delhi.
Q8. To display the name and balance due of those clients who belongs to Rajasthan.
Maharaja Agrasen Institute of Management
Studies Affiliated to GGS IP University; Recognized u/s 2(f)
of UGC Recognized by Bar Council of India; ISO 9001:
2015 Certified Institution Sector 22, Rohini, Delhi -110086,
India; www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
Delete all the records from Persons table who belong to Delhi CO4
1
Display all the records from Client_Master table who belongs to
2
Delhi and the Baldue is less than 5000.
3 Display all the records from Client_Master table where city= delhi
or gurugram.
4 Display all those records from Client_Master Table whose state
is Uttarpradesh and city must be Noida or Ghaziabad.
5 Display all the records from Client_Master table who don’t belong
to Delhi
6 Display distinct city values from Client_Master table.
ASSIGNMENT – 3
Q1. To delete persons from persons table who belongs to New Delhi.
Syntax:
DELETE from persons where city=’New Delhi;
Q2. To display from all records from client_master who belongs to Delhi and his or her
baldue is less than 5000.
Syntax:
select * from client_master where state='delhi' and baldue<5000;
Q3. To display all record from table client_master whose city belongs to new Delhi or Hisar.
Syntax:
select * from client_master where city='new delhi' or city='hisar';
Q4. To display all record from table client_master whose states belongs to Uttar Pradesh
and city belongs to Noida and Ghaziabad.
Syntax:
select * from client_master where State= 'uttar pradesh' and City = 'Noida' or State =
'uttar pradesh' and City = 'Ghaziabad';
Q5. To display all record from table client_master who don’t belong to city New Delhi
Syntax
select * from client_master where not city='new delhi';
Syntax
select distinct city from client_master;
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Course/ Subject Code: BCOM307 Subject Title: Information System Management Lab
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
1 Create a table with the following column names using NOT NULL: CO1,CO3,C
• Col1 O4
• Col2
3 Create a table table_1 using PRIMARY KEY and show that it doesn’t
accept any duplicate values. Also use a command to DESCRIBE the
table.
4 Show all the records from table_1.
5 Delete a row from a table whose Col1 value is “234”.
6 Show the distinct values of Col1.
ASSIGNMENT – 4
QUES 1 Create a table with the following column names using NOT NULL:
Col1
Col2
Questi Question CO
on
No.
No.
1 Hansen Ola 30
2 Svendson Tove 23
3 Petterson Kari 20
1 77895 3
2 44678 3
3 22456 2
4 24562 1
. Insert values in Order table with personID= ‘4’.
2
3 Insert values in Order table as:
● OrderID = 5
● OrderNumber = 12345
Also show all the values of the Order table.
During online education mode, upload scanned copy of the complete assignment including
cover page latest by due date.
Questi Question CO
on No.
No.
1 Create the table departments using the following the following columns and CO1
insert any 4 values in the table:
2 Create a table Employees using the following columns and insert any 3 values
in it:
● Emp_No INT (make this as primary key), also CHECK that the
Employee number should be between 1000 and 2000.
● Emp_NameVARCHAR(20)
● DesgVARCHAR(20), CHECK that the designation should be among the
following:
▪ Saleman
▪ Analyst
▪ Manager
▪ President
● Hire_date DATE
● Salary INT, CHECK that the salary should be >=1000 and <=5000. ●
Commission INT
● Dept_No INT (make this as the foreign key with reference to the
department table), CHECK that the dept_no should be among the
following:
▪ 10
▪ 20
▪ 30
▪ 40
ASSIGNMENT – 6
Q1. Create a table with the following columns: -
1. Dept_No (Primary key).
2. Dept_Name with the constraints that it should Sales, Marketing, IT, or Accounting.
3. Location with the constraints that it should be Delhi, Mumbai, Noida Gurgaon.
Syntax:
Create table
Department( Dept_No int
primary key,
Dept_Name varchar (25) not null check(Dept_Name=’Sales’ OR
Dept_Name=’Marketing’ OR Dept_Name=’IT’ OR Dept_Name=’Accounting’),
Location varchar (20) check(Location=’Delhi’ OR Location=’Mumbai’ OR
Location=’Noida’ OR Loaction=’Gurgaon’));
2. Emp_Name.
3. Designation with the constraint that it should be Clerk, Salesman, Analyst, Manager or
President.
4. Hire_Date.
5. Salary with the constraint that it should be between 1000 and 5000.
6. Commission.
7. Dept_No with the constraint that it should be 10, 20, 30, or 40 and it should be foreign
key with reference to Dept_No in Department table.
SYNTAX:
create table Employee(
Emp_No int primary key check(Emp_No>=1000 and Emp_No<=2000),
Emp_Name varchar(20),
.
Question CO
Question
No. No.
Add email column in the Persons table. CO1,CO2
1
Drop the column email from the persons table.
2
Questi Question CO
on
No.
No.
Update the city to mumbai of client from client master whose ClientID is 1001. CO2,C
1 O3,CO
4
2 Update the baldue to 10000 of all clients whose city is delhi from client
master.
3 Update the baldue to 10000 for all the clients from client master.
Add a new column of salary with datatype INT in client master table.
5
6 To insert a new row in client master table.
Update the salary to 10000 for ClientID 1001 in client master.
7
1 To delete all those records from client master where city is Mumbai and
2 baldue is greater than 10000.
QUES 2 Update the baldue to 10000 of all clients whose city is delhi from client
master.
QUES 3 Update the baldue to 10000 for all the clients from client master.
QUES 12 Delete all records from client_master table where city is Mumbai and baldue is
greater than 10000
QUES 13 Update the name to smith city to Chandigarh and baldue to 5000 where client_no
is 102
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Question CO
Question
No. No.
1 Create a table name client_test having fields: CO1,CO2,C
• Name O3
• City
• Basic Salary
From the source table name Client_Master.
2 Truncate table client_test
4 Find out all the names of all the clients from table client_master.
Delete from client_master where column state holds the value Haryana.
8
Truncate table empties a table completely logically it is equivalent to delete statement that
deletes all row but there are some differences
1 Truncate draw and recreate the table which is much faster than deleting rows 1 by
1 2 Truncate operations are not transaction safe
3 The number of deleted rows is not returned
Q2 Truncate table client_test
Q3 Renaming tables
Q8 delete from client_master where column state holds the value haryana
Q9 add a column called telephone of data type int in the client_master table
Question CO
Question
No. No.
List all the clients whose salary is between 5000 to 10000. CO4
1
3 List the customers whose names have the second character as ‘a’.
List the customers whose names have the second character as ‘a’ OR
4
‘r’.
List the customers whose name begin with the letters ‘ab’ and it a four
5
letter word.
6 . List the customer details of the costumers named RISHUB, KRITI,
ABHI and RAHUL.
. List the customer details of the customer named other than RISHUB,
7 KRITI, ABHI and RAHUL.
8 List the client who stay in a city whose first letter is ‘m’.
List all clients whose baldue is greater than 1000 OR less than equal to
10
5000.
ASSIGNMENT 10
IN or NOT IN predicate
The arithmetic operate equal compare the
In case the value needs to be compared to a list of values the IN PREDICATE is used
The IN PREDICATE helps reduce the need to use multiple or conditions
Q6 list the customer details of the customers name smith, shivam, rohan, manav
Syntax – Select * from client_bcom5a where name IN(‘smith’,’shivam’,’rohan’,’manav’);
Q7 list the customer details of the customers not name smith, shivam, rohan, manav
Q10 List all clients whose baldue is greater than 1000 and less than or equal to 5000
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Question CO
Question
No. No.
Add 10 more days to the date 2017-06-15 and return the date. CO2,CO3,C
1 O4
List the emp_no, emp_name and hire_date when they have joined the
4
organization from the employees table.
. List the month of the employees hire date from the employees table.
5
6 Subtract 15 days from the employees hire date from the employees
table.
7 List the employees whose salary is more than 1000 from the employees
table.
Ques 4 List the employee number, name, hire date from table employees
Ques 5 List the month of employees hire date from table employees;
Ques 6 Subtract 15 days from the employees hire date from the employees table.
Ques 7 List the employees whose salary is more than 1000
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Questi Question CO
on
No.
No.
● Baldue should be 0
(3rd row)
7 Display all records from client_master5b table for those clients whose name
starts with ‘I’.
Client_no
Name
City
Pincodex
State
Baldue
Q2 insert 3 rows into the client_master table with the following values
Client no – C00001
Name – Ivan Biros
City – Mumbai
Pin code – 400054
State – Maharashtra
Bal due – 15000, 0 & 5000
And here the client no is primary key
Q3 change the city of client_no C00001 to Bangalore
Q4 change the bal due of client number C0001 to 1000
Q7 display all records from the client_master table for those clients whose name start with I
Q8 retrieve the entire contents of client_master table
Find the average salary of employees from the employees_bcom table. CO4
1
2 Find the average salary of all distinct values of employees from the
employees_bcom table.
11 List the employees whose salary is more than 1000, calculate a new
salary as original salary x 0.15, rename the new column in the output of
above query as new salary in the employees_bcom table.
ASSIGNMENT 13
AVERAGE FUNDTION – Returns an average value of n ignoring null values
SYNTAX – AVG([DISTINCT
QUES 1 To find the average salary of all employees from employee_bcom table
QUES 6 To display the average salary of all employee whose hire date is greater than 1st jan
2011
QUES 7 list the name of all employees whose salary is greater than 2000 and commission
value equals to 1000
QUES 8 list the name of all employees having ‘h’ as second letter in their name and whose
salary is greater than 4000
QUES 9 To count the number of employees having commission less than or equal to 500
QUES 10 Determine the maximum and minimum commission of employee_bcom table and
rename the output as max_commission & min_commission
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Questi on Question CO
No.
No.
1 list the employees from the employees table whose salary is more than 1000 CO4,C
calculate a new salary as original salary into .15 rename the new column in the O5
output of above query as new salary
2 Show the employee name in ascending order of their names in the employees table.
3 select all records from the employee table sorted in descending order by the name of
the employee
4 Find out how many employees are there in each designation in the employees table
5 To count the no. Of clients in each city from client _master table.
6 To show all designation from employees table where the no. Of employees is more
than 3.
7 To count the no. Of employees in each designation where the designation name start
with “p” and the no. Of employees is more than 1 in the employees table.
8 To count the no. Of clients in each city where the baldue is more than 1000 from
client master table
ASSIGNMENT 14
Ques 1 List the employees whose salary is more than 3500 and calculate a new salary as
original salary * 0.15, rename the new column in the output of above query as new_salary
ORDER BY CLAUSE, Syntax – select col1, col2 from table name order by ASC/DESC;
QUES 3 Select all record from the employee table sorted descending order by the name of
employee
QUES 4 Find out how many employees are there in each designation
GROUP BY CLAUSE – The group by clause is another section of select statement, this
optional clause tells DBMS to group rows based on distinct values that exist for specified
columns. The group by clause creates a dataset containing several sets of records grouped
together based on a condition.
Syntax – Select <col1>, <col2>, <col3> Aggregate function (<expression>) from table
name where <condition> group by <col1>, <col2>, <col3>;
QUES 5 To count the no. of clients in each city from the client_bcom5a table
QUES 6 To show all designation from employee table where no of employee is more than 1
HAVING CLAUSE – The having clause can be used with consumption with group by
clause, having imposes a condition on the group by clause which further filters the group
created by the group by clause
QUES 7 To count the number of employees in each designation where the designation name
starts with s and the number of employees is more than 1
QUES 8 To count the no of client in each city where whose balance due is more than 1000
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
1 Retrieve the details of employees whose department location is Delhi. CO4,CO5
.
To count the number of employees in each department location.
2
Find out the name of employees whose department does not belongs to
3
Delhi.
To display the number of employees in each department location.
4
ASSIGNMENT – 15
Sub queries (nested queries)
A sub query is a form of a SQL statement that appears inside another sql statement. It is
also termed as nested query. The statement containing a sub query is called a parent
statement. The parent statement uses the rows (that is the result set returned by the sub
query).
It can be used for the following:
• To insert records in a target table.
• To create tables and insert records in the table created.
• To update records in a target table.
• To provide values for conditions in where, having, in, with select, update and delete
statements.
Q3 Find out the name of Employees whose department does not belong to Delhi
Q4 To display the number of employees in each department Location.
Q5 To display the number of employees in each department no, where average salary of
employee is more than 2000
Q6 To display the name of employees whose department location is either Delhi or Mumbai.
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Questi Question CO
on
No.
No.
1 List the employee details along with the department to which they CO1,C
belong. O2,CO
3,CO4
.
2 To show the employee name and dept name for those employees whose
name start with a.
3 To display the employee details along with department details for those
employees whose name second letter is “I” and order by dept name.
7 Write a sql command to display the name, salary, dept_id for those
employees who work in the same designation as the employee work
whose employee id is 1001
8 Write the sql command to display the name, salary, dept_no for those
employees who earn such amount of salary which is smallest salary of
any of the department.
1 Write sql command to display all info of the employees whose salary is
0 within the range 1000 and 5000.
ASSIGNMENT-16
Join Statement:
A single SQL sentence can manipulate data from more than one tables. Joins are used to
achieve this.
i. Tables are joined on columns that have the same datatype and data width in the
tables.
ii. Tables in a database can be related to each other with ease.
iii. A primary key is a column with a unique value for each row.
iv. The purpose is to bind data together across tables without repeating all of the
data in every table.
Types of Join:
1. Inner Join
2. Outer Join (left, right and full):
3. Cross Join
Inner join:
Inner Join are also known as equi-join because the where statement generally compares two
columns from two tables with equivalence operator. The syntax is given below:
SELECT col1, col2, col3 from table_name1
INNER JOIN table_name2
ON table_name1.col1= table_name2.col2
WHERE condition
ORDER BY col1, col2, col3
TASK 3
Display the Employee details along with the department details for those employees whose
names’ second letter is A and order by department name.
TASK 4
Add a new column location in Employee table.
Steps:
TASK 5
Display the employee details whose location is same as the department location.
TASK 6
Write the SQL command to display the name for those employees who get more salary than
the employees where Employee No is 1001.
TASK 7
Write SQL command to display the name, salary, department ID for those employees who
shares the same designation as the employee whose Employee No is 1001.
TASK 8
Write SQL command to display the name, salary, department no of those employees who
earn such amount of salary which is the least in every department.
TASK 9
Display all the information of employees whose employee no is any of the numbers
1001,1002,1003.
TASK 10
Display all the information of employees whose salary is within the range 1000 and 5000.
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Question CO
Question
No. No.
1 Display all the information of the employees whose salary is within the CO2,CO3,C
range of smallest salary and 2500. O4
.
2 To display the no of employees in each department with their department
name
3 Display the emp name, emp id and job title for all employees whose dept
location is delhi.
4 Write sql command to display query name and job title for all employees
whose salary is more than average salary of any department.
To display the emp name whose location is same as the dept location
5
ASSIGNMENT – 17
TASK 1
Display all information of employees whose salary is within the range of least salary and
2500.
TASK 2
Display the no of employees in each dept with their dept names.
TASK 3
Display the employee name, employee id and designation for all employees whose
department location is Delhi.
TASK 4
Employee name and job title for all employees whose salary is more than average salary of
any department.
TASK 5
Display the employee name whose location is same as the Department location.
Maharaja Agrasen Institute of Management Studies
Affiliated to GGSIP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015 Certified
Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Assignment No.18
Questi on Question CO
No.
No.
1 CO
1,C
CustomerID CustomerName Address City Cou O2
ntry
Ger
1 AlfredsFutterkiste Maria Obere Str.
Berlin 12209 man
Ander 57
y
s
05021 Mexi
co
Avda. de la
2 Ana Trujillo Ana Trujillo México
Constitución
Emparedados y helados D.F.
2222
Shi
pp
OrderID CustomerID EmployeeID OrderDate
erI
D
10308 2 7 1996-09-18 3
10309 2 3 1996-09-19 1
10310 1 8 1996-09-20 2
3 Write a sql statement that will select all the customers and any orders they
might have
4 To display the department location and employee location which have matched
with employee location or not.
List the employee details who have the same location as department location.
5
List all customer name who has placed order after jan 1996.
6
ASSIGNMENT-18
Outer join
i. Outer joins are similar to inner joins but give more flexibility when selecting
data from related tables.
ii. This type of joins can be used in situations where it is desired to select all rows
from the table on the left or right regardless of whether the other has values in
common and usually enter null where data is missing.
Left join
i. The left join keyword returns all records from the left table (table1), and the
matched records from the right table (table2).
ii. The result is null from the right side if there is no match.
The syntax for left join is:
SELECT column_name(s)
FROM table1
TASK 1
Create the two tables given below, assigning respective Primary and Foreign keys and
giving the required datatype.
TASK 2
Write a SQL statement that will select all customers and any orders they might have.
Right Join
i. The right join keyword returns all records from the right table (table1), and the
matched records from the left table (table2).
ii. The result is null from the left side if there is no
match. The syntax for right join is given below
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;
TASK 3
To display the department location and employee location who have matched with
employee location or not.
TASK 4
List the employee details who have same location as of department location.
TASK 5
List all customer names who have placed order before January 1996.
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
To display Cartesian product of employee table (self-employee table). CO3,CO4.C
1 O5
To display all the employees who locate in the same city
2
ASSIGNMENT-19
Cross join
It is also called cartesian product. In this, all the records of the first table comes with all the
records from the second table.
Self join
in self-join, a table is joined with itself. For this, two copies of the table have to be opened
in the memory. In the FROM clause, the table name needs to be mentioned twice. Since the
table names are the same, the second table will overwrite the first table and in effect result
in only one table being in memory.
Syntax:
SELECT * or column_name FROM
<table_name>[<alias1>],<table_name>[<alias2>].............;
TASK 1
Display the Cartesian product of Employees_Bcom table. (Self-join)
TASK 2
Display all details of the employees who are located in the same city.
TASK 3
Create a table with the columns Emp_No, Dept_No and Since. Assign foreign keys to the
first two columns and insert 5 rows into it.
TASK 4
Find the Emp_No who is enrolled in at least two departments.
TASK 5
Calculate the average salary for each department.
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
Write sql query to print the details of all employees order by employee name CO2,CO3,C
1 ascending and department descending O4,CO5
write sql query to print details of all employees excluding names Ananaya
2
and Himanshi from employee table.
3 write sql query to print the details of all employees whose name contain a.
write sql query to print details of all employees Whose name ends with
4 h and contains 6 alphabets.
write sql query to fetch no of employees in each department in the
5 descending order
6 write sql query to fetch the list of employees with same salary.
7 write sql query to show second highest salary from the employee table
8 write sql query to fetch the departments that have less than 2 people in it.
ASSIGNMENT-20
TASK 1
Write an SQL query to print the details of all employees ordered by employee name in
ascending and department name in descending order.
TASK 2
Write SQL query to print the details of all employees excluding names Ruby and Caleb
from Employees_Bcom table.
TASK 3
Write SQL query to print the details of all employees whose name contains ‘a’.
TASK 4
Write SQL query to print the details of all employees whose name ends with h and contains
6 alphabets.
TASK 5
Write SQL query to fetch number of employees in each department in descending order.
TASK 6
Write an SQL query to fetch the list of employees with the same salary.
Steps:
Since my table does not have employees with same salary, I used the update command to
make their salaries same first.
TASK 7
Write an SQL query to show the second-highest salary from the Employee table.
TASK 8
Write an SQL query to fetch the departments that have less than 2 people in it.
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Questi on Question CO
No. No.
1 CO1,C
O2
Column_Name Data Type Size Default Attributes
start with C
CITY VARCHAR 15
PINCODE INTEGER
STATE VARCHAR 15
BALDUE INTEGER
Create the following table with the given attributes:
Table Name: CLIENT_MASTER
2
CLIENT_ NAME CITY PINC STATE BALD
NO ODE UE
CITY VARCHAR 20
PINCODE INTEGER
STATE VARCHAR 20
CANCELLED,
FULFILLED, BACK_
ORDER
Create the following table with the given attributes:
Table Name: SALES_ORDER
8
QTYORDERED INTEGER
O19001 P00001 4
O19002 P00001 10
O19003 P0345 4
O46865 P07865 1
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
Print the description and total qty sold for each product. CO3,CO4,C
1 O5
listing of product whose selling price is more than 500 with the
2
new selling price calculated as original selling price + .15%.
listing of name, city and state of client who are not in the state of
Maharashtra.
3
7 Determine the max and min price for the product prices.
ASSIGNMENT – 22
Using Having and Group by Clauses
Q1. Print the description and total quantities sold for each product.
Syntax:
-> SELECT PM .DESCRIPTION, SUM(SOD.QTY_Ordered) FROM
PRODUCT_MASTER PM,
-> SALES_ORDER_DETAILS SOD
-> WHERE PM.PRODUCT_NO = SOD.PRODUCT_NO
-> GROUP BY DESCRIPTION;
Output:
Q2. Listing of Product whose selling price is more than 500 with the new selling price
calculated as original selling price +15%;
Syntax: Select Description, Sell_Price*0.15 “NEW_PRICE” From Product_master where
sell_price>500;
Output:
Q3. Listing the name city and state of client who are not in the state of Maharashtra.
Syntax: Select Name,City,state from client_master where NOT(State='Maharashtra');
Output:
Q7. Determine the max and min for the product prices.
Syntax: Select Max(Sell_price),Min(Sell_price) from product_master;
Output:
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
1 Draw an E-R diagram for an university database application where – A CO6
university has many departments, Each department has multiple
instructors, one among them is the head of the department, an instructor
belongs to only one department, each department offers multiple courses,
each of which is taught by a single instructor, A student may enroll for
many courses offered by different departments.
Table:
Département table: ID(Primary key), name, Course ID(For.)
Course table: Course ID (Primary key), NAME
Instructor table: ID (Primary key), name, Course ID(For.), Department ID(For.)
Student table: ID (Primary key), Name, Course ID(For.)
Syntax:
Course table: Create table Course(
-> CourseID INT Primary Key,
-> Name Char (20));
Department Table: Create table Department_ER(
-> DeptID INT Primary key,
-> Dept_Name Char(20),
-> CourseID INT,
-> Foreign Key (CourseID) References Course(CourseID));
Instructor table: Create table Instructor(
-> InstrctorID INT Primary key,
-> Name Char (20),
-> CourseID INT,
-> DeptID INT,
-> Foreign Key (CourseID) References Course(CourseID),
-> Foreign Key (DeptID) References Department_ER(DeptID));
Student table: Create table Student(
-> Student_ID INT Primary Key,
-> Name Char(20),
-> CourseID INT,
-> Foreign Key (CourseID) References Course(CourseID));
Output:
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Question CO
Question
No. No.
1 Insert the two values in each of the following tables. CO1,CO2,C
• Courses table O3
• Department table
• Instructor table
• Student table
4 Show the student names who belongs to the course content writing.
6 List the customer name, address, city, pincode for the clients who has
placed orderno. ‘O19001’.
Q2 To delete a reord from instructor name ‘Rohit’ from the instructor table
Syntax: Delete from instructor where Name='Rohit';
Output:
Note: ON DELETE SET NULL
A foreign Key with a SET NULL ON DELETE Means that if a record in the parent table is
deleted then the corresponding record in the child table will have will have the foreign key
field set to NULL. The records in the child table will not be deleted.
Q3. To delete a course from course table.
Syntax: Delete from course where CourseID=1001;
Q6 List the customer name, city and pincode for the client who has places order Number
019001
Syntax: select name,city,pincode from client_master,sales_order where order_no = 'O19001'
and sales_order.client_no = client_master.client_no;
OR
select name,city,pincode from client_master where Client_No In(select client_No from
sales_order where Order_No='O19001');
Q7 To add a new column QtyDisc in sales_order_details table and update the values
accordingly.
Syntax:
Alter table: Alter table sales_order_details
-> Add Column QtyDisc INT;
Update table: Update sales_order_details
-> Set QtyDisc= 7
-> where Order_No='O19001';
Q8. Print the description and total quantity sold for each product.
Syntax: select Description, Sum(Qtydisc) from product_master PM, Sales_order_details
SOD
-> Where PM.product_no= SOD.Product_No
-> Group by Description;
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
1 Create an E-R diagram of ‘LIBRARY MANAGEMENT SYSTEM’. CO6
.
Convert this ER diagram into the relational tables.
2
ASSIGNMENT – 25
Q1. To design an ER diagram for library management system.
ER Diagram:
Tables:
Books: ISBN(Primary Key), Title, Price, Staff_ID (Foreign Key), Reader_ID (Foreign Key)
Publisher: Publisher_ID (Primary Key),Name ,Year, ISBN(Foreign Key)
Reader: Reader_ID (Primary Key), name ,address
Staff: Staff_ID (Primary Key),name,
Reports: Reg_no(Primary key),book no, Issue/return, Staff_ID (Foreign Key)
Tracking Reader: Staff_ID (Foreign Key) and reader_ID (Foreign Key)
Syntax's:
1) Reader table:
Create table
Reader( Reader_ID INT
Primary Key, Name Char
(20),
Address Varchar (25));
2) Staff table:
Create table
Staff( Staff_ID INT
Primary Key, Name Char
(20));
3) Reports Table:
Create table
Reports( Registration_No INT
Primary Key, Book_No INT,
Issue_or_Return Date,
Staff_ID INT,
Foreign Key (Staff_ID) References Staff(Staff_ID));
4) Books Table:
Create table
Books( ISBN INT
Primary Key, Title
Varchar (25), Price
INT,
Staff_ID INT,
Reader_ID INT,
Foreign Key (Staff_ID) References Staff(Staff_ID),
Foreign Key (Reader_ID) References Reader(Reader_ID));
5)Publisher Table:
Create table
Publisher( Publisher_ID INT
Primary Key, Name Varchar
(25),
Year Date,
ISBN INT,
Foreign Key (ISBN) References Books(ISBN));
6) Tracking Reader table:
Create table
Tracking_Reader( Staff_ID
INT,
Reader_ID INT,
Foreign Key (Staff_ID) References Staff(Staff_ID),
Foreign Key (Reader_ID) References Reader(Reader_ID));
Output:
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
Question CO
Question
No. No.
Write a sql query for printing the first three characters of the column CO2,CO3,C
1 employee name. O4,CO5
Write a sql query for fetching the unique values of the column city from the
2
employee table.
Write a sql query for printing the name from employee table after the removal of
3
white spaces from right side.
Write a sql query for printing the name from employee table after the removal of
4
white spaces from left side.
Write a sql query for printing the name after replacing A with a.
5
6 Write a sql query for printing all details of employee which ordered by name
ascending.
7 Write a sql query for printing all details of employee which order by name
ascending and department in descending.
Write a sql query printing all details of employee excluding the names of ananya
8
and himanshi
Write a sql query to print name of employee whose name ends with a
9
Write an sql query for printing the details of employee whose hired in may 2017.
10
Q2 Write an SQL query for fetching the unique values of the column Location from the
employee table.
Syntax: Select Distinct(Location) from employee_bcom;
Output:
\
Q3 Write an SQL query for fetching the name of employee from employee table after
removing the white spaces from the right side
Syntax: Select RTRIM(Emp_name) from employee_bcom;
Output:
Q4 Write an SQL query for fetching the name of employee from employee table after
removing the white spaces from the left side
Syntax: Select LTRIM (Emp_name) from employee_bcom;
Output:
Q5 write a sql query for printing the name after replacing captial A with small a.
Syntax: select Replace(Emp_Name,'a','A') from employee_bcom;
Ouput:
Q6 write a sql query all details of employee which order by name ascending.
Syntax: select * from employee_bcom order by emp_name asc;
Output:
Q7 write a sql query all details of employee with order by name ascending and department
in descending.
Syntax: Select E.Emp_Name, D.Dept_Name
-> From employee_bcom E
Q10 write an sql query for printing the details of employees who were hired in JULY 2019.
Syntax: select * from employee_bcom where hire_date like '2019-07%';
Output:
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
List the various product available from the product_master table. CO2,CO3,C
1 O4,CO5
List the clients who are located in Mumbai.
2
Listing of products whose selling price is more than 500 with the new selling price
7
calculated as original selling price + 15%.
Count the no of products having price>=500.
8
Determining the maximum and minimum price for the product prices.
10
ASSIGNMENT – 27
Q1. List the various product available from the product_master table.
Syntax: select Description from product_master;
Q7 Listing of product whose selling price is more than 500 with the new selling price
calculated as orginal selling price +15%.
Syntax: select product_No, description,sell_price,(sell_price)*1.15 "new SP" from
product_master where sell_price>500;
Q10. Determining the maximum and minimum price for the product prices.
Syntax: select Max(Sell_price)"Max Sp", Min(Sell_price)"Min SP", Max(Cost_Price) "Max
CP", MIN(Cost_Price) "MIN CP" from product_master;
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
Printing the description and total qty sold for each product. CO2,CO3,C
1 O4,CO5
Finding the non moving products i.e product not being sold.
2
Find the name and complete address for the customer who have placed order no.
3
O19001.
Add a new column product rate in the table sales_order and update the values.
4
Find the names of clients who have placed order worth rs. 1000 or more.
5
ASSIGNMENT – 28
Q1. Printing the description and total quantity sold for each product.
Syntax: Select description, SUM(QTY_Ordered) from Product_master PM,
Sales_order_details SOD Where PM.Product_no =SOD.Product_No Group By Description;
Output:
Q2. Finding the Non-moving product I.e. product not being sold.
Syntax: Select Product_No, Description FROM Product_Master where Product_No NOT
IN(Select Product_No from Sales_Order_Details);
Output:
Q3. Find the name and complete address for the customer who has placed order number
O19001.
Syntax: select Name,city,State,Pincode FROM Client_Master Where Client_No IN(Select
Client_NO From Sales_Order where Order_No='O19001');
Q4 Add a new column product rate in the sales_order_details and update the values.
Syntax:
1) Alter table Sales_order_details Add column Product_Rate INT;
2) update sales_order_details SET Product_Rate = 800 where order_NO='O19002';
Output:
Q5 Find the names of clients who have placed worth rupees 1,000 or more.
Syntax: Select Distinct(name) from client_master where Client_No IN(select Client_No
from sales_order where order_No IN(select order_no from sales_order_details where
QTY_Ordered*Product_Rate >=1000));
Output:
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
Prepare a list of employee name, dept name and their cities for the employee and CO4,CO5
1 department who belongs to the same city.
Prepare a list with orderno, clientname and their cities for those order which taken
2
between jan 2005- jan 2006.
Wwrite a sql statement to know which employee are working for which department.
3
List all information from the sales_order table for order placed in the month of June.
4
Write a sql command to prepare a list in ascending order for the salesman who have
5
either one or more order or not yet have any order.
Prepare a list of employee name, dept name and their cities for the employee and
6
department who belongs to the same city.
ASSIGNMENT – 29
Q1 Prepare a list of employee name, department name and their cities for the employee and
department who belong to the same city.
Syntax:
-> select e.Emp_name,D.Dept_name, D.Location
-> from employee_bcom E, Department D
-> where E.Location=D.Location;
Q2 Write a sql command to list the order no, client name and their cities for those order
whose which taken between jan,2003 to jan,2005.
Syntax: select C.Name,C.City,S.Order_No
-> from client_master C,sales_order S
-> where S.Client_No=C.Client_No
-> And S.Order_date Between '2003-01-01' and '2005-01-01';
Q3 Write a SQl Statement to know which employee are working for which department.
Q4 List all information from sales_order table for the order placed in the month of july.
Syntax: select * from sales_order where Month(Order_date)=07;
Q5 Write A SQL command to prepare a List in ascending order for the sales man who have
either one or more order or not yet have any order.
Syntax: select A.Salesman_Nmae,B.Order_No
-> from sales_master A Left Outer join sales_order B
-> On A.Salesman_No=B.Salesman_No;
Maharaja Agrasen Institute of Management Studies
Affiliated to GGS IP University; Recognized u/s 2(f) of UGC
Recognized by Bar Council of India; ISO 9001: 2015
Certified Institution Sector 22, Rohini, Delhi -110086, India;
www.maims.ac.in
During online education mode, upload scanned copy of the complete assignment
including cover page latest by due date.
Question CO
Question
No. No.
Draw an E-R diagram for an e-commerce site who sells the product online. CO6
1
Convert the E-R diagram into tables accordingly.
2
Primary key
2) Item Table
Item_No Name Price
Primary Key
3) Order Table
Order_No Item_No
4) Shopping Cart
Item_No Customer_ID
5)Company
Name Item_No
Foreign Key