083 Anshika Jain Ism Practical File
083 Anshika Jain Ism Practical File
SUBMITTED BY SUBMITTED TO
Name: Anshika Jain Dr. Anamika Rana
Enrollment No:
08314901719
BBA (G) IV(B) MORNING
1
INDEX
DML Commands
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
Q2- Insert the following data into their
respective tables:
4.
5
and their salary is not equal to 1000, 3000, or
5000.
• 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.
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.
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.
11
ASSIGNMENT 1
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.
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
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
BLOB(size) For BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data
MEDIUMBLOB For BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data
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:
15
Q. Create a table student with fields: Roll No., Name, Course and Date of Birth
and display its structure.
Q. Create table Employee with fields: EmpID, EmpName, Designation and Date
of Joining.
16
Creating the table:
CODE:
OUTPUT:
17
ASSIGNMENT 2
1. Create a table with fields: CID, Name, Fname, city, Pincode, state.
18
5. Display Fname, Name and state.
19
8. Display records where the pin is not entered.
20
11. Display records of Delhi or Karnataka.
21
14. Use alias names to display CID.
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.
23
22. Delete those customers who do not have a pin code.
24
25
ASSIGNMENT 3
Q1. create the following tables:
1. Client_master
Client_no Varchar2 6
Name Varchar2 20
Address 1 Varchar2 30
Address 2 Varchar2 30
City Varchar2 15
State Varchar2 15
Pincode number 6
Input:
Output:
26
2. Product_master
Input:
Output:
Input
27
Output:
Input:
28
Output:
Input:
Output:
29
Output:
Input:
Output:
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:
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.
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:
34
1. Retrieve the list of managers.
Input:
Output:
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:
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:
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:
Input:
Output:
Output:
Input:
Output:
43
23. Select the minimum and maximum salary from the EMP
table.
Input:
Output:
Output:
Output:
44
ASSIGNMENT 5
Q. What is the ER Model? Explain Entity, Attribute, and relation with their
types and shapes.
● Provide a preview of how all your tables should connect, what fields are
going to be on each table.
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
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.
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.
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
example, a lecture might have attributes: time, date, duration, place, etc. An
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.
2. 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
54
ASSIGNMENT 9
• S_no
• NAME
• CITY
• AGE
• MARKS
Output:
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:
Output:
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
CODE:
59
Find average and total salaries of all employees
Input:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Update the commission to 10%of salary for all the employees having salary
greater than 50000
CODE:
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:
Output:
62
List average salary of each job excluding managers
Input:
Output:
Output:
63
ASSIGNMENT 11
Output:
Output:
Output:
Output:
65
ASSIGNMENT 12
Output:
Output:
Output:
Output:
67
ASSIGNMENT 13
Create the following table CUSTOMER having the columns, data types.
68
• Display customer details having designation Sales Representative.
Input:
Output:
Output:
Output:
Output:
69
Output:
70
ASSIGNMENT 14
71
1. Delete the records of the employee whose Emp_id is 101
Input:
Output:
Output:
72
3. Delete the record of the employee whose name begins with S or salary
>10000
Input:
Output:
Output:
5. Update the record of the employee, set salary to 15000 where Dept_name is
IT.
Input:
Output:
73
ASSIGNMENT 15
74
Output:
Output:
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:
76
Output:
Display the employee id, name, salary and designation for the employees
where emp_grade is A.
Input:
Output:
77