0% found this document useful (0 votes)
240 views77 pages

083 Anshika Jain Ism Practical File

This document contains instructions for completing assignments on SQL and relational database concepts. It includes tasks to create tables, insert data, modify table structures, perform queries using SQL commands like SELECT, UPDATE, DELETE. It also covers entity relationship modeling and normalization. Students are asked to create tables, draw ER diagrams and perform queries on sample databases for student management, hospital management, e-commerce systems. Aggregate functions, joins and grouping are also practiced on tables with employee data.

Uploaded by

Shivam
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
240 views77 pages

083 Anshika Jain Ism Practical File

This document contains instructions for completing assignments on SQL and relational database concepts. It includes tasks to create tables, insert data, modify table structures, perform queries using SQL commands like SELECT, UPDATE, DELETE. It also covers entity relationship modeling and normalization. Students are asked to create tables, draw ER diagrams and perform queries on sample databases for student management, hospital management, e-commerce systems. Aggregate functions, joins and grouping are also practiced on tables with employee data.

Uploaded by

Shivam
Copyright
© © All Rights Reserved
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/ 77

GURU GOBIND SINGH INDRAPRASTHA UNIVERSITY

MAHARAJA SURAJMAL INSTITUTE

Information Systems Management Lab


Subject Code-BBA-212

SUBMITTED BY SUBMITTED TO
Name: Anshika Jain Dr. Anamika Rana
Enrollment No:
08314901719
BBA (G) IV(B) MORNING

1
INDEX

S.NO ASSIGNMENT PAGE DATE SIGN


NO.
1. What is SQL? Features of SQL

Basics of SQL & DDL Commands

1. Data types in SQL


2. Create table student with fields: Roll
No., Name, Course and Date of Birth
and display its structure.
3. Modify the structure of student table
a. Add two new columns named
Section and Contact No.
b. Change the size of course column
by 2 points.
c. Remove the column Date of Birth.

1. Create table Employee with fields:


EmpID, EmpName, Designation and
Date of Joining
1. Modify the structure of Employee table
a. Add a new column salary.
b. Change the size of Salary by 5 points
and Name by 10 Points.
c. Remove the fields Designation and Date
of Joining.

2. Create table customer with fields: CID,


Lname,Fname,city,Pin,State

DML Commands

1. Insert 5 rows each using all the three


methods
2. Display the contents
3. Display CID and Fname
4. Display Fname,Lname and state
5. Display all records where state is Delhi

2
6. Display fname, lname concatenated with
state
7. Display the records whose pin is not
entered
8. Display the states to which the customer
belongs
9. Select records of Delhi having name
Rajiv
10. Display records delhi or Karnataka
11. Display details of Customer with
CID=98
12. Display details of Customer except
CID=98
13. Use Alias Name to display CID
14. Retrieve all rows where CID is
between 98 and 100
15. Display those rows where state
name begins with ‘D’
16. Retrieve all rows where first name
contains the word’RAJ’
17. Retrieve all rows where name field
contains the word’RA ESH’
18. Retrieve all rows where city is
Delhi, Karnataka or Bangalore
19. Rename the table customer to
cust
20. Delete all those rows of customers
who stay in Bangalore
21. Delete those customers who do
not have Pin Code
22. Rename column city to address
23. Delete the customers who do not
belong to Bangalore

3. Q1. Create the following tables:

3
Q2- Insert the following data into their
respective tables:

Q3:- On the basis of above two tables answer


the following Questions:
i) Find out the names of all the clients.
ii) Retrieve the list of names and cities of all
the clients.
iii) List the various products available from the
product_master table.
iv) List all the clients who are located in
Bombay.
v) Display the information for client no 0001
and 0002.
4
vi) Find the products with description as ‘1.44
drive’ and ‘1.22 Drive’.
vii) Find all the products whose sell price is
greater than 5000.
viii) Find the list of all clients who stay in in city
‘Bombay’ or city ‘Delhi’ or
‘Madras’.
ix) Find the product whose selling price is
greater than 2000 and less than or
equal to 5000.
x) List the name, city and state of clients not in
the state of ‘Maharashtra’.

4.

create an EMP table with given attributes and


constraints. Enter 10 records and perform
following given query:
1. Retrieve a list of MANAGERS.

2. Find out salary of both MILLER and SMITH.

3. Find out the names and salaries of all


employees earning more than 1000 per
month.

4. Display the names and salaries of all


employees except JAMES.

5. List the name and salary of employees who


can earn more than 1500 and are in
department 10 or 30. Label the columns
Employee and Monthly Salary respectively.

6. List the name and salary for all employees


whose salary is not in the range of 1500 and
2850.

7. Display the name, job, and salary of all the


employees whose job is CLERK or ANALYST

5
and their salary is not equal to 1000, 3000, or
5000.

9. Display the name of all employees who


have two Ls in their name and are in
department 30 or their manager is 7782.

10. Find out the details of employees whose


names begin with ‘S’.

11. Find out the names of all employees that


have ‘A’ anywhere in their name.

12. Find out the names of all employees that


have ‘L’ as their third character in their name.
15. List employee number, employee name,
total salary (i.e. salary + commission). (Note:
Manipulate the NULL values accordingly.)

16. List the name of the employee and


designation of the employee, who does not
report to anybody.

17. List employee name and yearly salary and


arrange the output on the basis of yearly
salary in descending order.

18. Retrieve the names of departments in


ascending order and their employees in
descending order.

19. Select the name, job, salary, and


department number of all employees except
SALESMAN from department number 30.

20. Print the total employees and average


salary of each department.

21. Select the minimum and maximum salary


from EMP table.

22. List the minimum and maximum salaries of


each department.

23. List all departments in which more than 3


employees are working.
6
5. What is ER Model? Explain Entity, Attribute,
and relation with their types and shapes.
6. Draw an ER Diagram and Relational Schema
for an e-commerce site that sells the product
online.
7. Draw an ER Model and Relational Schema for
a Hospital Management System.
8. Draw an ER Model and Relational Schema for
a University Management System.
9. Create a table named as STUDENT with the
following fields as:

• S_no
• NAME
• CITY
• AGE
• MARKS
Execute the following queries after entering 10
records in the table.
• Display all the details of the given table
• Display the names in alphabetical order
• Display the name along with the marks
where marks are greater than 60
• Display the name of students whose name
starts with letter ‘A’.
• Display the details of students who live in
‘Delhi’.
• Display the details of students who are older
than 15 years.
• Display the S_no of those students whose
names starts with L and ends
with A or marks less than 70
• Display the name and S_no of those
students who have scored marks equal
to 95
• Display the names and marks of all those
students who have scored marks
between 75 and 90.

10. Aggregate and grouping Functions

Create table employee empno,ename(Not


Null),salary(Not Null), Commission,Job,
Deptno.

7
Perform the following operations:
1. Insert 5 records in employee table
2. Find average and total salaries of all
employees
3. Find average and total salaries of each
employee
4. Find minimum salary of Manager
5. Find the maximum salary of the Manager
6. How many employees are Managers
7. Add 50% salary to salary column and name
it HRA
8. Count the total no. employees
9. Count the no. of departments available
10. Count the no. of employees in each
department
11. Update the commission to 10%of salary
for all the employees having salary greater
than 50000
12. Find the name of lowest paid employee for
each manager
13. Update the salaries of all employees in
department 10 by hiking it by 15%.
14. Find the difference between highest and
lowest salaries for each dept
15. List average salary for all the depts which
have more than 5 People
16. List jobs of all the employees where
maximum salary is more than 40000
17. List jobs and no. of employees in each job
18. List average salary of each job excluding
managers
19. List total, Max, Min, Average salary of
employee’s job wise.

11. Create a table Student with following fields


• Enrolment_no
• S_name
• Course_id
• Batch
• Semester
Execute the following queries after entering 10
records in the table.
• Display the list of Students in batch ‘2017-
2020’
• Display the Enrolment_no of fourth semester
students.
8
• Display the list of students of batch ‘2017-
2020’ and course_is 17.
• Display the number of students in course_id
44.

12. Create table course with following fields


• Course_id
• Course_name
• Duration
Execute the following queries after entering 10
records in the table.
• Create a relationship of Course table with
Student table which is created in
previous exercise.
• Display all students enrolled in BBA course.
• Display name of students enrolled in 2 year
course.
• Display details of students of BBA course of
batch ‘2017-2020’.

13. Create the following table CUSTOMER having


the columns, data types.

Field Name Data Type


Customer_ID Number
Customer_Name Text
Designation Text

City Text
Country Text
Phone Number
Insert the data into table Customer. And apply
the queries:
• Display customer details having designation
Sales Representative
• Retrieve customer who is living in Canada
• Show details of the customer whose name is
Victoria
• Show detail of the customer who lives in
Sweden.
• Show detail of the customer who is owner.

14. Create a table EMPLOYEE either the following


fields:
• Emp_id
• Emp_name
9
• Dept_name
• Salary
• Add
• Date of joining
Perform the following queries on it.
1. Delete the records of the employee whose
Emp_id is 101
2. Delete the record of the employees whose
Dept_name is HR and salary >10000
3. Delete the record of the employee whose
name begins with S or salary >10000
4. Update the record of the employees, set
Dept_name = IT where Dept_name is
PRODUCTION.
5. Update the record of the employee, set
salary to 15000 where Dept_name is IT.

15. Create a table employee with the following


fields: Emp_id, Emp_name, Contact
no, Gender, Salary, Emp_grade, Designation,
Address

Execute the following queries on the table


created:

1. Display the details of the employees


2. Display the employee id of employee whose
name is supriya.
3. Display the name of the employee whose
contact no. is 98454863011.
4. Display the details of the employee whose
address is MSI, C-4, Janakpuri.
5. Display the name of the employees whose
salary is greater than 10,000.
6. Update the employee details, set
EMP_GRADE equal to C whose salary is less
than 10000.
7. Delete the record of the employee whose
gender is male and designation is
manager
8. Display the name, designation, and salary
of all the employees whose names
begins with A.
9. Update the employee details; set
designation to assistant manger where
designation is trainee.
10
10.Display the employee id, name, salary and
designation for the employees where
emp_grade is A.

11
ASSIGNMENT 1

Q. What is SQL? Features of SQL.


SQL stands for Structured Query Language. A query language is a kind of
programming language that's designed to facilitate retrieving specific information
from databases, and that's exactly what SQL does. To put it simply, SQL is the
language of databases.
SQL can be used to share and manage data, particularly data that is found in
relational database management systems, which include data organized into tables.
Multiple files, each containing tables of data, also may be related together by a
common field. Using SQL, you can query, update, and reorganize data, as well as
create and modify the schema (structure) of a database system and control access
to its data.
Structured Query Language is more straightforward than other more complex
programming languages. It is typically easier for beginners to learn SQL than it is for
them to pick up languages such as Java, C++, PHP, or C#.

Features of SQL:
1. High Performance
SQL provide high performance programming capability for highly transactional,
heavy workload and high usage database system. SQL programming gives
various ways to describe the data more analytically.

2. High Availability
SQL is compatible with databases like MS Access, Microsoft SQL Server,
MySQL, Oracle Database, SAP HANA, SAP Adaptive Server, etc. All of
these relational database management systems support SQL and it is easy to
create an application extension for procedural programming and various other
functions which is additional features thus converting SQL into a powerful tool.

3. Scalability and Flexibility


SQL provide Scalability and Flexibility. It is very easy to create new tables and
previously created or not used tables can be dropped or deleted in a
database.

4. Robust Transactional Support


With SQL programming can handle large records and manage numerous
transactions.

5. High Security
It is very easy to provide permissions on tables, procedures, and views hence
SQL give security to your data.
12
6. Comprehensive Application Development
SQL is used by many programmers to program apps to access a database.
No matter what is the size of organization, SQL works for every small or large
organization.

7. Management Ease
SQL is used in almost every relational database management system. “Select
“, “Create”, “Insert”, “Drop”, “Update”, and “Delete” are the standard and
common SQL commands that helps us to manage large amount of data from a
database very quickly and efficiently.

8. Open Source
SQL is an open-source programming language for building relational database
management system

Q. Data types in SQL.


SQL data types can be broadly divided into following categories.
1. Numeric data types such as int, tinyint, bigint, float, real etc.
2. Date and Time data types such as Date, Time, Datetime etc.
3. Character and String data types such as char, varchar, text etc.
4. Unicode character string data types, for example nchar, nvarchar, ntext etc.
5. Binary data types such as binary, varbinary etc.
6. Miscellaneous data types – clob, blob, xml, cursor, table etc.

Data type Description

CHAR(size) A FIXED length string (can contain letters, numbers, and special characters).
The size parameter specifies the column length in characters - can be from 0 to
255. Default is 1

VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and special
characters). The size parameter specifies the maximum column length in
characters - can be from 0 to 65535

BINARY(size) Equal to CHAR(), but stores binary byte strings. The size parameter specifies
the column length in bytes. Default is 1

13
VARBINARY(size) Equal to VARCHAR(), but stores binary byte strings. The size parameter
specifies the maximum column length in bytes.

TINYBLOB For BLOBs (Binary Large OBjects). Max length: 255 bytes

TINYTEXT Holds a string with a maximum length of 255 characters

TEXT(size) Holds a string with a maximum length of 65,535 bytes

BLOB(size) For BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data

MEDIUMTEXT Holds a string with a maximum length of 16,777,215 characters

MEDIUMBLOB For BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data

LONGTEXT Holds a string with a maximum length of 4,294,967,295 characters

LONGBLOB For BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data

ENUM (val1, val2, A string object that can have only one value, chosen from a list of possible
val3, ...) values. You can list up to 65535 values in an ENUM list. If a value is inserted
that is not in the list, a blank value will be inserted. The values are sorted in the
order you enter them

SET (val1, val2, val3, A string object that can have 0 or more values, chosen from a list of possible
...) values. You can list up to 64 values in a SET list

14
Q. Create table student with fields: Roll No., Name, Course and Date of Birth
and display its structure.
Modify the structure of student table
• Add two new columns named Section and Contact No.
• Change the size of course column by 2 points.
• Remove the column Date of Birth.

CODE:

OUTPUT:

a. Adding new columns:

b. Change size of Course column by 2 points.

c. Drop Date of Birth column

15
Q. Create a table student with fields: Roll No., Name, Course and Date of Birth
and display its structure.

Create the table:

Modify the table:


a. Add two new columns: Section and Contact no.

b. Change the size of course column by 2 points.

c. Remove the column Date of Birth.

Q. Create table Employee with fields: EmpID, EmpName, Designation and Date
of Joining.
16
Creating the table:
CODE:

OUTPUT:

Modify the table:


a. Add a new column: “Salary”.

b. Change the size of salary by 5 points and Name by 10 points.

c. Remove the fields “Designation” and “Date of joining”.

17
ASSIGNMENT 2

1. Create a table with fields: CID, Name, Fname, city, Pincode, state.

2. Insert 5 rows each using all three methods.

3. Display the contents.

4. Display CID and Fname.

18
5. Display Fname, Name and state.

6. Display all records where the state is Delhi.

7. Display Fname, Name concatenated with state.

19
8. Display records where the pin is not entered.

9. Display the states to which the customers belong.

10. Select record of Delhi having name Rajesh.

20
11. Display records of Delhi or Karnataka.

12. Display details of the customer with CID=98.

13. Display details of customers except CID=98.

21
14. Use alias names to display CID.

15. Retrieve all rows where CID is between 98 and 100.

16. Display those rows where state name begins with “D”.

22
17. Retrieve all rows where the first name contains the word “RAJ”.

18. Retrieve all rows where the name field contains “Ra_esh”.

19. Retrieve all rows where the city is Delhi, Karnataka or Bangalore.

20. Rename table customer to cust.

21. Delete the rows of customers who stay in Bangalore.

23
22. Delete those customers who do not have a pin code.

23. Rename column city to address.

24. Delete customers who do not belong to Bangalore.

24
25
ASSIGNMENT 3
Q1. create the following tables:

1. Client_master

Column Name Data type Size

Client_no Varchar2 6

Name Varchar2 20

Address 1 Varchar2 30

Address 2 Varchar2 30

City Varchar2 15

State Varchar2 15

Pincode number 6

bal_due number 10, 2

Input:

Output:

26
2. Product_master

Input:

Output:

Q2. Insert the following data in the respective table.


Client no Name City Pincode State Bal_due

0001 Ivan Bombay 400054 Maharashtra 15000

0002 Vandana Madras 780001 Tamil Nadu 0

0003 Pramada Bombay 400057 Maharashtra 5000

0004 Basu Bombay 400056 Maharashtra 0

0005 Ravi Delhi 100001 2000

0006 Rukmini Bombay 400050 Maharashtra 0

Input

27
Output:

Input:

28
Output:

Q3. Answer the following questions.

1. Find out the names of all the clients.

Input:

Output:

2.Retrieve the list of names and cities of all the clients.


Input:

29
Output:

3. List the various products available from the product_master


table.

Input:

Output:

4. List all the clients located in Bombay.

Input:

Output:

30
5. Display the information of client no 0001 and 0002.

Input:

Output:

6. Find the products with description “1.44 drive” and “1.22 drive”.

Input:

Output:

7. Find the products whose sell price is greater than 5000.

Input:

Output:

8. Find the list of clients who stay in the city ‘Bombay’ or ‘Delhi’ or
‘Madras’.

Input:

31
Output:

9. Find out the products whose sell price is greater than 2000 and
less than or equal to 5000.

Input:

Output:

10. List name, city and state of clients not in the state of
Maharashtra.

Input:

Output:

32
ASSIGNMENT 4

Q1. Create the following table and enter the values given.

Name Null? Type

EMPNO Not null int

ENAME varchar2(10)

JOB varchar2(9)

MGR int

HIREDATE Date

SAL int

COMM int

DEPTNO int

CREATING TABLE:

33
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPT
NO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10

INPUT:

OUTPUT:

Answer the following questions.

34
1. Retrieve the list of managers.

Input:

Output:

2. Find out the salary of both MILLER and SMITH.

Input:

Output:

3. Find out the names of all employees earning more than 1000
per month.
Input:

Output:

35
4. Display the names and salaries of all employees except
JAMES.
Input:

Output:

5. List the name and salary of employees who can earn more than
1500 and are in department 10 or 30. Label the columns Employee
and Monthly Salary respectively.
Input:

36
Output:

6. List the name and salary for all employees whose salary is not in
the range of 1500 and 2850.
Input:

Output:

7. Display the name, job, and salary of all the employees whose job
is CLERK or ANALYST and their salary is not equal to 1000, 3000,
or 5000.
Input:

Output:

37
8. Display the name, salary and commission for all employees
whose commission amount is greater than their salary increased
by 10%.
Input:

Output:

9. Find out the details of employees whose names begin with


‘S’.
Input:

Output:

10. Find out the details of employees whose names begin with
‘S’.

Input:

Output:
38
11. Find out the names of employees who have ‘A’ anywhere in their name.
Input:

Output:

12. Find out the names of all employees that have ‘L’ as the
third character in their name.
Input:

Output:

13. Find out the names of employees whose names begin with ‘A’
or ‘M’.
Input:

Output:

39
14. List all the employees whose commission is
NULL.
Input:

Output:

15. List employee number, employee name, total salary (salary+commission).


(Note: Manipulate null values accordingly.)
Input:

Output:

40
16. List the names and designation of all the employees who do
not report to anybody.
Input:

Output:

17. List employee name and yearly salary and arrange the output
on the basis of yearly salary in descending order.
Input:

Output:

41
18. Retrieve the names of departments in ascending order and
their employees in descending order.
Input:

Output:

42
19. Select the name, job, salary and department number of
all employees except SALESMAN from department number
30.
Input:

Output:

20. List different jobs with no duplicates.

Input:

Output:

21. Count the total number of employees.


Input:

Output:

22. Print the total employees and average salary of each


department.

Input:

Output:

43
23. Select the minimum and maximum salary from the EMP
table.
Input:

Output:

24. List the minimum and maximum salaries of each


department.
Input:

Output:

25. List all the departments in which more than 3 employees


are working.
Input:

Output:

44
ASSIGNMENT 5

Q. What is the ER Model? Explain Entity, Attribute, and relation with their
types and shapes.

Entity Relationship Diagram, also known as ERD, ER Diagram or ER model, is a


type of structural diagram for use in database design. An ERD contains different
symbols and connectors that visualize two important pieces of information: The
major entities within the system scope, and the inter-relationships among these
entities. And that's why it's called the "Entity" "Relationship" diagram (ERD). It is a
high-level data model and develops a simple and easy design to view data.

ER model helps to systematically analyse data requirements to produce a well-


designed database. The ER Model represents real-world entities and the
relationships between them. Creating an ER Model in DBMS is considered as a
best practice before implementing your database.

Why to use the ER model?

● Helps you to define terms related to entity relationship modelling.

● Provide a preview of how all your tables should connect, what fields are
going to be on each table.

● Helps to describe entities, attributes, relationships.

● ER diagrams are translatable into relational tables which allows you to


build databases quickly.

● ER diagrams can be used by database designers as a blueprint for


implementing data in specific software applications.

● The database designer gains a better understanding of the information


to be contained in the database with the help of ERP diagram.

45
● ERD Diagram allows you to communicate with the logical structure of the
database to users

COMPONENTS OF ER

ENTITY
An entity can be a place, person, object, event or a concept, which stores data in the
database. The characteristics of entities must have an attribute, and a unique key.
Every entity is made up of some 'attributes' which represent that entity.

Examples of entities:

46
● Person: Employee, Student, Patient
● Place: Store, Building
● Object: Machine, product, and Car
● Event: Sale, Registration, Renewal
● Concept: Account, Course

WEAK ENTITY:

An entity not having the ability to be uniquely identified by its attributes is a weak
entity. Weak entities rely on the relationship with other entities. A double rectangle
represents a weak entity in the ER diagram. For example – a bank account cannot
be uniquely identified without knowing the bank to which the account belongs, so a
bank account is a weak entity.

RELATIONSHIP

Relationship is nothing but an association among two or more entities. Entities


take part in relationships. We can often identify relationships with verbs or verb
phrases. A diamond or rhombus is used to represent relationships.

TYPES OF RELATIONSHIPS:

1. One to One
One entity from entity set X can be associated with at most one entity of entity
set Y and vice versa.

Example: One student can register for numerous courses. However, all those
courses have a single line back to that one student.

47
2. One to Many

One entity from entity set X can be associated with multiple entities of entity set
Y, but an entity from entity set Y can be associated with at least one entity.

For example, one class is consisting of multiple students.

3. Many to One

More than one entity from entity set X can be associated with at most one entity of
entity set Y. However, an entity from entity set Y may or may not be associated
with more than one entity from entity set X.

For example, many students belong to the same class.

48
4. Many to Many

One entity from X can be associated with more than one entity from Y and vice
versa.

For example, Students as a group are associated with multiple faculty members,
and faculty members can be associated with multiple students.

ATTRIBUTE

It is a single-valued property of either an entity-type or a relationship-type. For

example, a lecture might have attributes: time, date, duration, place, etc. An

attribute in ER Diagram examples, is represented by an Ellipse.

TYPES OF ATTRIBUTES

1. Simple Attribute

49
A simple attribute contains an atomic value which cannot be further divided. It is
simply represented by an oval. A simple attribute is directly connected to the
entity type. While making the E-R diagram, we directly connect the oval with the
rectangle.

For example, Roll_no of Student, Age of Student. It is represented in the E-R


diagram as:

2. Composite Attribute

A Composite attribute can be further divided into other attributes. We represent


this in the E-R diagram by connecting an oval with an oval i.e the composite
attribute is also represented by an oval and the further divided attribute all also
represented by ovals. When we convert this E-R diagram to the relational table
then we don't have any column of the composite attribute. We have a column only
for the attribute which came after we further divided the composite attribute.

For example, Name of a student can be further divided into first name, middle
name and last name. The composite attribute name is also represented by oval
as well as the other attributes are also represented by oval and we connect all the
further divided attributes with the composite attribute. In the table, we will have
three columns i.e. First_name, Middle_name, and Last_name. There is no such
column called "Name".

3.
Derived Attribute

50
The value of this attribute is derived from some other attributes. We know the
value of some other attribute(stored attribute)and from the stored attribute, we
are deriving the value of this attribute(derived attribute). This is done mainly
because the value for such attributes keeps on changing. It is represented by a
dashed oval.

For example, The value of age attribute is derived from the DOB(date of birth)
attribute.

4. Multi-valued Attribute

This attribute has more than one value. It is represented by a double oval. Some
Composite keys can also be a multivalued attribute. For example, the address
attribute of a student can further be divided into ‘Locality’, ‘Town’ and ‘PIN’. So, we
call it a composite attribute. Also, the address of a student can have more than
one value. A Student can have more than one Address i.e Permanent Address
and Temporary Address. So, it can also be called a multivalued attribute.

For example, A student can have more than one email address.

51
ASSIGNMENT 6

Draw an ER Diagram and Relational Schema for an e-commerce site that sells the
product online.

52
ASSIGNMENT 7

53
ASSIGNMENT 8

Draw an ER Model and Relational Schema for a Hospital Management


System.

54
ASSIGNMENT 9

Q. Create a table named as STUDENT with the following fields as:

• S_no
• NAME
• CITY
• AGE
• MARKS

Execute the following queries after entering 10 records in the table.


• Display all the details of the given table
• Display the names in alphabetical order
• Display the name along with the marks where marks are greater than 60
• Display the name of students whose name starts with letter ‘A’.
• Display the details of students who live in ‘Delhi’.
• Display the details of students who are older than 15 years.
• Display the S_no of those students whose names starts with L and ends
with A or marks less than 70
• Display the name and S_no of those students who have scored marks equal
to 95
• Display the names and marks of all those students who have scored marks
between 75 and 90.

CREATING THE TABLE:

• Display all the details of the given table


55
Input:

Output:

• Display the names in alphabetical order


Input:

Output:

• Display the name along with the marks where marks are greater than 60.
Input:

Output:

56
• Display the name of students whose name starts with letter ‘A’.
Input:

Output:

• Display the details of students who live in ‘Delhi’.


Input:

Output:

• Display the details of students who are older than 15 years.


Input:

Output:

57
• Display the S_no of those students whose names starts with L and ends
with A or marks less than 70.
Input:

Output:

• Display the name and S_no of those students who have scored marks equal
to 95.
Input:

Output:

• Display the names and marks of all those students who have scored marks
between 75 and 90.
Input:

Output:

58
ASSIGNMENT 10

Aggregate and grouping Functions

Create table employee empno,ename(Not Null),salary(Not Null), Commission,Job,


Deptno.
Perform the following operations:
1. Insert 5 records in employee table
2. Find average and total salaries of all employees
3. Find average and total salaries of each employee
4. Find minimum salary of Manager
5. Find the maximum salary of the Manager
6. How many employees are Managers
7. Add 50% salary to salary column and name it HRA
8. Count the total no. employees
9. Count the no. of departments available
10. Count the no. of employees in each department
11. Update the commission to 10%of salary for all the employees having salary
greater
than 50000
12. Find the name of lowest paid employee for each manager
13. Update the salaries of all employees in department 10 by hiking it by 15%.
14. Find the difference between highest and lowest salaries for each dept
15. List average salary for all the depts which have more than 5 People
16. List jobs of all the employees where maximum salary is more than 40000
17. List jobs and no. of employees in each job
18. List average salary of each job excluding managers
19. List total, Max, Min, Average salary of employee’s job wise.

Create table employee empno,ename(Not Null),salary(Not Null),


Commission,Job, Deptno.

CODE:

Insert 5 records in employee table.

59
Find average and total salaries of all employees
Input:

Output:

Find average and total salaries of each employee


Input:

Output:

Find minimum salary of Manager


Input:

Output:

Find the maximum salary of the Manager


Input:

Output:

How many employees are Managers?


Input:

Output:

Add 50% salary to salary column and name it HRA


Input:
60
Output:

Count the total no. employees


Input:

Output:

Count the no. of departments available


Input:

Output:

Count the no. of employees in each department


Input:

Output:

Update the commission to 10%of salary for all the employees having salary
greater than 50000
CODE:

Find the name of lowest paid employee for each manager


Input:

Output:
61
Update the salaries of all employees in department 810 by hiking it by 15%.
Code:

Find the difference between highest and lowest salaries for each dept
Input:

Output:

List average salary for all the depts which have more than 5 People

Input:

List jobs of all the employees where maximum salary is more than 40000
Input:

Output:

List jobs and no. of employees in each job


Input:

Output:

62
List average salary of each job excluding managers
Input:

Output:

List total, Max, Min, Average salary of employee’s job wise.


Input:

Output:

63
ASSIGNMENT 11

Create a table Student with following fields


• Enrolment_no
• S_name
• Course_id
• Batch
• Semester
Execute the following queries after entering 10 records in the table.
• Display the list of Students in batch ‘2017-2020’
• Display the Enrolment_no of fourth semester students.
• Display the list of students of batch ‘2017-2020’ and course_is 17.
• Display the number of students in course_id 44.

CREATING THE TABLE:

• Display the list of Students in batch ‘2017-2020’


Input:

Output:

• Display the Enrolment_no of fourth semester students.


64
Input:

Output:

• Display the list of students of batch ‘2017-2020’ and course_is 17.


Input:

Output:

• Display the number of students in course_id 44.


Input:

Output:

65
ASSIGNMENT 12

Create table course with following fields


• Course_id
• Course_name
• Duration
Execute the following queries after entering 10 records in the table.
• Create a relationship of Course table with Student table which is created in
previous exercise.
• Display all students enrolled in BBA course.
• Display name of students enrolled in 2-year course.
• Display details of students of BBA course of batch ‘2017-2020’.

CREATING THE TABLE:

• Create a relationship of Course table with Student table which is created in


previous exercise.
Input:

Output:

• Display all students enrolled in BBA course.


66
Input:

Output:

• Display name of students enrolled in 2-year course.


Input:

Output:

• Display details of students of BBA course of batch ‘2017-2020’.


Input:

Output:

67
ASSIGNMENT 13

Create the following table CUSTOMER having the columns, data types.

Field Name Data Type


Customer_ID Number
Customer_Name Text
Designation Text
City Text
Country Text
Phone Number
Insert the data into table Customer. And apply the queries:
• Display customer details having designation Sales Representative
• Retrieve customer who is living in Canada
• Show details of the customer whose name is Victoria
• Show detail of the customer who lives in Sweden.
• Show detail of the customer who is owner.

CREATING THE TABLE:

68
• Display customer details having designation Sales Representative.
Input:

Output:

• Retrieve customer who is living in Canada.


Input:

Output:

• Show details of the customer whose name is Victoria.


Input:

Output:

• Show detail of the customer who lives in Sweden.


Input:

Output:

• Show detail of the customer who is owner.


Input:

69
Output:

70
ASSIGNMENT 14

Create a table EMPLOYEE either the following fields:


• Emp_id
• Emp_name
• Dept_name
• Salary
• Add
• Date of joining

Perform the following queries on it.


1. Delete the records of the employee whose Emp_id is 101
2. Delete the record of the employees whose Dept_name is HR and salary >10000
3. Delete the record of the employee whose name begins with S or salary >10000
4. Update the record of the employees, set Dept_name = IT where Dept_name is
PRODUCTION.
5. Update the record of the employee, set salary to 15000 where Dept_name is IT.

CREATING THE TABLE:

71
1. Delete the records of the employee whose Emp_id is 101
Input:

Output:

2. Delete the record of the employees whose Dept_name is HR and salary


>10000
Input:

Output:

72
3. Delete the record of the employee whose name begins with S or salary
>10000
Input:

Output:

4. Update the record of the employees, set Dept_name = IT where Dept_name


is PRODUCTION.
Input:

Output:

5. Update the record of the employee, set salary to 15000 where Dept_name is
IT.
Input:

Output:

73
ASSIGNMENT 15

Create a table employee with the following fields: Emp_id, Emp_name,


Contact
no, Gender, Salary, Emp_grade, Designation, Address

Execute the following queries on the table created:

1. Display the details of the employees


2. Display the employee id of employee whose name is supriya.
3. Display the name of the employee whose contact no. is 98454863011.
4. Display the details of the employee whose address is MSI, C-4, Janakpuri.
5. Display the name of the employees whose salary is greater than 10,000.
6. Update the employee details, set EMP_GRADE equal to C whose salary is less
than 10000.
7. Delete the record of the employee whose gender is male and designation is
manager
8. Display the name, designation, and salary of all the employees whose names
begins with A.
9. Update the employee details; set designation to assistant manger where
designation is trainee.
10.Display the employee id, name, salary and designation for the employees where
emp_grade is A.

CREATING THE TABLE:

Display the details of the employees


Input:

74
Output:

Display the employee id of employee whose name is supriya.


Input:

Output:

Display the name of the employee whose contact no. is 98454863011.


Input:

Output:

Display the details of the employee whose address is MSI, C-4, Janakpuri.
Input:

Output:

Display the name of the employees whose salary is greater than 10,000.
Input:

75
Output:

Update the employee details, set EMP_GRADE equal to C whose salary is less
than 10000.
CODE:

Delete the record of the employee whose gender is male and designation is
Manager
Input:

Output:

Display the name, designation, and salary of all the employees whose names
begins with A.
Input:

Output:

Update the employee details; set designation to assistant manager where


designation is trainee.
Input:

76
Output:

Display the employee id, name, salary and designation for the employees
where emp_grade is A.
Input:

Output:

77

You might also like