Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 117

GURU GOBIND SINGH INDRAPRASTHA UNIVERSITY

MAHARAJA SURAJMAL INSTITUTE

Information Systems Management Lab


Subject Code-BBA-212

SUBMITTED BY SUBMITTED TO
Syed Hassan Mehdi Dr. Anamika Rana
Enrollment No: 02114901719
BBA (G) IV(A)
INDEX
S. Page
Assignment Date Sign
No. No.
1 What is SQL? Features of SQL 9-25 26 Feb,
2021
Basics of SQL & DDL Commands
1. Data types in SQL
2. Create table student with fields: Roll
3. No. , Name, Course and Date of Birth
4. and display its structure.
5. 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, 26-40 26 Feb,
Lname,Fname,city,Pin,State 2021

DML Commands

1. Insert 5 rows each using all the three methods


2. Display the contents
3. Display CID and Fname

30 February
26, 2021

4. Display Fname,Lname and state


5. Display all records where state is Delhi
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’RAESH’
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: 41-52 27 Mar,


2021

Q2- Insert the following data into their respective tables:

Q3:- On the basis of above two tables answer the


following
Questionries:
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.
vi) Find the products with description as ‘1.44 drive’ and
‘1.22 Drive’.
vii) Find all the products whose sell price is greater then
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 53-68 3 April,
2021

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 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.
22. Print the total employees and average salary of each
department.
23. Select the minimum and maximum salary from EMP
table.
24. List the minimum and maximum salaries of each
department.
25. List all departments in which more than 3 employees
are working.

5 What is ER Model? Explain Entity, Attribute, and relation 69-74 26 April,


with their types and shapes. 2021
6 Draw an ER Diagram and Relational Schema for an e- 75 26 April,
commerce site that sells the product online. 2021
7 Draw an ER Model and Relational Schema for a Hospital 76 26 April,
Management System. 2021
8 Draw an ER Model and Relational Schema for a 77 26 April,
University Management System. 2021
9 Create a table named as STUDENT with the following 78-83 27 May,
fields as: 2021

• 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 84-92 27 May,
2021
Create table employee empno,ename(Not Null),salary(Not
Null), Commission,Job, Deptno.

104 May, 27 2021

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 employees job
wise
11 Create a table Student with following fields 93-95 2 June,
• Enrolment_no 2021
• 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.

12 Create table course with following fields 120 June, 2 96-99 3 June,
2021
Course_id
S_name
Course_name
Batch
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 100-103 3 June,
columns, data types. 2021

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: 104-106 3 June,


• Emp_id 2021
• Emp_name
• Dept_name
• Salary
• Add

128 June, 2
2021

• Date of joining
Perform the following queries on it.
1. Show the records of the employee whose Emp_id is 101
2. Display 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: 107-112 3 June,


Emp_id, Emp_name, 2021
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.
Assignment 1

Q. Explain the following terms:

1. DATA
In general data is facts and statistics collected together for reference or
analysis.
Whereas in DBMS
Data is any sort of information which is stored in computer memory. This
information can later be used for a website, an application or any other client
to store for future purpose. The most common information is User
information in the form of user personal, address and banking information.
Let’s consider the example of Facebook, it stores our personal data, images,
posts, comments and many more things. Banking application also stores user
data, their transactions details, funds summary etc. All this information is
data, but when it put together and store in a structural way, it becomes
informational data.
But, how do these applications or websites get data? When you post a status
on Facebook, perform a banking transaction online or upload a selfie on
Instagram, you are actually sending data to the site or to be precise their
server. So, we can say any information transmitted or transferred is actually
data.

2. DATABASE
Database (DB) are organized, they have a structure, and all the data they
store it fits into that structure. More specifically, a database is an electronic
system that allows data to be stored, easily accessed, manipulated and
updated.
A database is made up of two components mainly, data and a meaningful
method for accessing and manipulating data. Without these two, a database
is just a random set of
data.
A more precise example of a database can be a dictionary, which stores a
large quantity of data as Key-Value pairs. At the same time, it also has a
meaningful method to access data using the Key.

Databases are quite similar to spreadsheets as they are mostly made up of


tables which contain rows and columns like a spreadsheet. A database needs
to be hosted or created on some special database platform, some of the
famous Database platforms are:

● PostgreSQL
● MySQL
● Microsoft Access
● SQLite

Types:
1. Relational Databases:
The easiest way to put relational databases is: They store data in form of
tables which are related to each other. For a further understanding, the
relational database model works on the concept of
storing data where data is represented by tuples, grouped into relations.
In mathematics, a tuple is defined as a finite-ordered list of elements. To
define in a simple language, a tuple is actually a row in the table of the
database. Each row in a table represents a set of related data, and every row
in the table has the same structure.
While the rows actually contain data in a related fashion, the columns
actually contain data of a similar kind, i.e., data in a column is always of a
similar kind.
So, we may see that storing the data in form of a table, we have two major
attributes, rows and columns.
Each table is related to a certain type of data and thus a table relates all the
various data types present inside it. Each data type actually defines a certain
new column and thus a new property is given to the table. The table relates
or combines all the columns present in the table to each other and thus the
data too. This leads to the fact that certain times tables are termed as
“relations” also
2. Hierarchical Database:
The Hierarchical databases are actually databases which follow a tree-like
structure. Just imagine a family hierarchy tree, maybe of an Ameoba-like
family, i.e., one parent dividing into multiple children.

3. Network Database:
Network databases are similar to Hierarchical ones, the only difference is
one child is connected to many parents. Just take a look at the example of an
E-Commerce company, where the children, Seller, and Customer both share
common child Product.

4. Object-Oriented Database:
An object-oriented database (OODBMS) or object database management
system (ODBMS) is a database that is based on object-oriented
programming (OOP). The data is represented and stored in the form of
objects. OODBMS are also called object databases
or object-oriented database management systems.

3. DBMS
A database management system is a software used to perform different
operations,like addition, access, updating, and deletion of the data, like
adding your name in the database for an online retail store as a customer.
A database management system acts as the backbone of a database and
makes using a database a cakewalk as it makes access and management of
data a lot easier. While database can provide the data to the website and have
a meaningful way to access data, it still cannot understand the language or
method which a website may use
to fetch the data, i.e., it cannot understand the commands on its own.
Thus, to tackle this problem, we bring in the concept of Database
Management System.
A DBMS understand the commands and the queries which define what data
is required by the App or Website and thus use the meaningful method of
accessing the database to
retrieve the information.
Therefore, it can be said that a DBMS act as connecting bridge between the
database and the user and DBMS actually understand the queries and help
database to understand the requirements.
4. RDBMS
Stands for Relational Database Management System. An RDBMS is a
DBMS designed specifically for relational databases. Therefore, RDBMSes
are a subset of DBMSes.
A relational database refers to a database that stores data in a structured
format, using rows and columns. This makes it easy to locate and access
specific values within the database. It is relational because the values within
each table are related to each other.
Tables may also be related to other tables. The relational structure makes it
possible to run queries across multiple tables at once.
While a relational database describes the type of database and RDBMS
manages, the RDBMS refers to the database program itself. It is the software
that executes queries on the data, including adding, updating, and searching
for values. An RDBMS may also provide a visual representation of the data.

5. FILE SYSTEM VS DBMS

S.
FILE SYSTEM DBMS
NO.
A file system is a DBMS or Database
software that manages Management System is a
and organizes the files in software application. It is
1
a storage medium. It used for accessing,
controls how data is creating, and managing
stored and retrieved. databases.
The file system provides
DBMS gives an abstract
the details of data
2 view of data that hides the
representation and
details
storage of data.
DBMS is efficient to use
Storing and retrieving of
as there are a wide variety
data can’t be done
3 of methods to
efficiently in a file
store and retrieve data.
system.
The file system doesn’t
DBMS provides a crash
4 have a crash recovery
recovery mechanism
mechanism.
Protecting a file system is very DBMS offers good
5
difficult. protection mechanism.
In a file management
The redundancy of data is
6 system, the redundancy
low in the DBMS system.
of data is greater.
Data inconsistency is low
Data inconsistency is
7 in a database management
higher in the file system.
system.
Not provide support for Easy to implement
8 complicated complicated
transactions. transactions.
The centralization Centralization is easy to
9 process is hard in File achieve in the DBMS
Management System. system.
There is no efficient You can easily query data
10 query processing in the in a database using the
file system. SQL language.

SQL
SQL is a domain-specific language used in programming and designed for
managing data held in a relational database management system, or for
stream processing in a relational data stream management system. SQL is
designed for a specific purpose: to query data contained in a relational
database. SQL is a set-based, declarative programming language, not
an imperative programming language like C or BASIC. However,
extensions to Standard SQL add procedural programming
language functionality, such as control-of-flow constructs.

FEATURE

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. High Security:
It is very easy to provide permissions on tables, procedures, and views hence
SQL give security to your data.

4. 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.

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

DATA TYPES

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
SMALLINT(size)
A small integer. Signed range is from -32768 to 32767.
Unsigned range is from
0 to 65535. The size parameter specifies the maximum
display width (which is 255)

MEDIUMINT(size)
A medium integer. Signed range is from -8388608 to
8388607. Unsigned range
is from 0 to 16777215. The size parameter specifies the
maximum display width (which is 255)

INT(size) A medium integer. Signed range is from -2147483648 to


2147483647.Unsigned range is from 0 to 4294967295.
The size parameter specifies the maximum display width
(which is 255)
INTEGER(size)
Equal to INT(size)
BIGINT(size)

A large integer. Signed range is from


-9223372036854775808 to
9223372036854775807. Unsigned range is from 0 to
18446744073709551615.The size parameter specifies
the maximum display width (which is 255)

FLOAT(size, d)

A floating point number. The total number of digits is


specified in size. The number of digits after the decimal
point is specified in the d parameter. This syntax is
deprecated in MySQL 8.0.17, and it will be removed in
future MySQL versions

FLOAT(p)

A floating point number. MySQL uses the p value to


determine whether to use FLOAT or DOUBLE for the
resulting data type. If p is from 0 to 24, the data type
becomes FLOAT(). If p is from 25 to 53, the data type
becomes DOUBLE()
DOUBLE(size, d)
A normal-size floating point number. The total number
of digits is specified in size. The number of digits after
the decimal point is specified in the d parameter

DATE A date. Format: YYYY-MM-DD. The supported range is


from 1000-01-01 to 9999-12-31
DATETIME(fsp) A date and time combination. Format: YYYY-MM-DD
hh:mm:ss. The supported range is from 1000-01-01
00:00:00 to 9999-12-31 23:59:59. Adding DEFAULT
and ON UPDATE in the column definition to get
automatic initialization and updating to the current date
and time

The SQL CREATE TABLE Statement


The CREATE TABLE statement is used to create a new table in a database.
Syntax
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);
The column parameters specify the names of the columns of the table.
The datatype parameter specifies the type of data the column can hold (e.g.
varchar, integer, date, etc.).

The SQL INSERT INTO Statement


The INSERT INTO statement is used to insert new records in a table.
INSERT INTO Syntax
It is possible to write the INSERT INTO statement in two ways.
The first way specifies both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
If you are adding values for all the columns of the table, you do not need to specify
the
column names in the SQL query. However, make sure the order of the values is in
the same
order as the columns in the table. The INSERT INTO syntax would be as follows:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);

QUESTION
Q1)
(A) Create table student with fields: Roll No., Name, Course and Date of Birth
and display its structure.

STEP-1 TYPE THE SYNTAX FOR CREATE TABLE USING RIGHT


COMMANDS
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);
STEP-2 TABLE IS CREATED

B) 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.

STEP-1 TYPE SYNTAX FOR ADDING COLUMNS USING ALTER


TABLE
ALTER TABLE table_name
ADD column_name datatype;
STEP-2 CHANGE THE WIDTH OF THE COLUMN USING THE ALTER
COLUMN SYNTAX
ALTER TABLE table_name
ALTER COLUMN column_name datatype;

STEP-3 REMOVE DATE OF BIRTH COLUMN FROM SYNTAX


ALTER TABLE table_name
DROP COLUMN column_name;
Q2.
A) Create table Employee with fields: EmpID, EmpName, Designation and Date of
Joining
STEP-1 TYPE THE SYNTAX FOR CREATE TABLE USING RIGHT
COMMANDS
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
….
);

STEP-2 TABLE IS CREATED


B) 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.

STEP-1 TYPE SYNTAX FOR ADDING COLUMNS USING ALTER TABLE


ALTER TABLE table_name
ADD column_name datatype;
STEP-2 CHANGE THE WIDTH OF THE COLUMN USING THE ALTER
COLUMN SYNTAX
ALTER TABLE table_name
ALTER COLUMN column_name datatype;

STEP-3 REMOVE DESIGNATION AND DATE OF JOINING COLUMN


FROM SYNTAX
ALTER TABLE table_name
DROP COLUMN column_name;
Assignment 2
Q) Create table customer with fields: CID,  Lname, Fname, city,
Pin,State 
SYNTAX
CREATE TABLE Customer
(
CID int,
LName varchar(255),
FName varchar(255),
city varchar(255),
pin varchar(255),
state varchar(255);
DML Commands
Insert 5 rows each using all the three  methods 
SYNTAX
INSERT INTO Customer (CID, Lname, Fname, city, pin, state )
VALUES (‘101’, ‘Sharma’, ‘Aman’, ‘Delhi’, ’4006221’, ‘New Delhi’),
(‘102’, ‘Kishore’, ‘Bharat’, ‘Bhopal’, ‘4006563’, ‘Madhya Pradesh’),
(‘103’, ‘Rana’, ‘Divya’, ‘Janakpuri’, ‘4006565’, ‘New Delhi’),
(‘104’, ‘Ahuja’, ‘Sudeep’, ‘Bhiwani’, ‘4006685’, ‘Haryana’),
(‘105’, ‘Kaur’, ‘Raman’, ‘Amritsar’, ‘4006231’, ‘Panjab’
);
Display the contents 
SYNTAX
SELECT * FROM [Customer]

Display CID and Fname


SYNTAX 
SELECT CID, Fname FROM [Customer]
Display Fname, Lname and state
SYNTAX
SELECT Fname, Lname, state FROM [Customer]

Display all records where state is New Delhi 


SYNTAX
SELECT * FROM [Customer] WHERE state=New Delhi
;
Display fname, lname concatenated  with state 
SYNTAX
SELECT Fname||” “||Lname||” “||state AS Address FROM Customer

Display the records whose pin is not  entered 


SYNTAX
SELECT * FROM [Customer] WHERE pin=’ ‘;
Since there’s no data where pin isn’t there thus it shows no result
Display the states to which the  
customer belongs 
SYNTAX
SELECT state FROM [Customer]

Select records of New Delhi having name Divya


SYNTAX
SELECT * FROM [Customer] WHERE Fname=’Divya’;

Display records delhi or Madhya Pradesh


SYNTAX
SELECT * FROM [Customer] WHERE state=’New Delhi’ OR ‘Haryana’;

Display details of Customer with  CID=102


SYNTAX
SELECT * FROM [Customer] WHERE CID=’102’;
Display details of Customer except  CID=102 
SYNTAX
DELETE FROM Customer WHERE CID=’102’;

Use Alias Name to display CID 


SYNTAX

SELECT CID AS ID, FName AS Customer


FROM Customer;
Retrieve all rows where CID is between  101 and 103
SYNTAX
SELECT * FROM [Customer] WHERE CID>’101’ AND CID<’103’;

Display those rows where state name begins with ‘D’


SYNTAX
SELECT * FROM Customer WHERE Fname LIKE ‘D%’;
Retrieve all rows where first name contains the word ’Ram’
SYNTAX
SELECT * FROM Customer WHERE Fname LIKE ‘Ram%’;

Retrieve all rows where First name field contains the word
“AMAN’
SYNTAX
SELECT * FROM [Customer] WHERE Fname=’Aman’;
Retrieve all rows where city is New Delhi, Haryana or Madhya Pradesh 
SYNTAX
SELECT * FROM [Customer] WHERE state=’New Delhi’; AND ‘Haryana’ AND
‘Madhya Pradesh’;

Rename the table customer to cust


SYNTAX
ALTER TABLE Customer
RENAME TO Cust;
BEFORE RUNNING SYNTAX

As you can see the table name in database is Customer


ATER RUNNING SYNTAX
The table name has changed to Cust

Delete all those rows of customers who stay in Haryana


SYNTAX
DELETE FROM Customer WHERE state=’Haryana’;

Delete those customers who do not have Pin Code 


SYNTAX
DELETE FROM Customer WHERE pin=’ ‘;

Since there’s no data where pin isn’t there thus it shows no change
Rename column city to address 
SYNTAX
ALTER TABLE Customer
RENAME city TO Address;
BEFORE RUNNING SYNTAX

ATER RUNNING SYNTAX

THE CITY COLUMN NAME HAS CHANGED TO ADDRESS


Delete the customers who do not belong to Madhya Pradesh
SYNTAX
DELETE FROM Customer WHERE state=’Madhya Pradesh’;
Assignment 3
Question 1
Create the following tables

i. CLIENT MASTER
SYNTAX
CREATE TABLE Client_master
(
Client_no varchar(6),
Name varchar2 (20),
Address1 varchar2 (30),
Address2 varchar2 (30),
City varchar2 (15),
State varchar2 (15),
Pincode number (6),
Bal_due number (10,2)
);
ii. PRODUCT MASTER
SYNTAX
CREATE TABLE Product_master
(
Product_no varchar2(255),
Description varchar2(255),
Profit_percent number,
Unit_measure varchar2(255),
Qty_on_hand number,
Reoder_lvl number,
Sell_price number,
Cost_price number
);
Question 2
Insert the information given.
i.

SYNTAX
INSERT INTO Client_master(Client_no, Name, City,
Pincode, State, Bal_due)
VALUES ('0001', 'Ivan', 'Bombay', '400054',
'Maharashtra', '1500'),
('0002', 'Vandana', 'Madras','780001','Tamilnadu', '0'),
('0003', 'Pramada', 'Bombay', '400057', 'Maharashtra',
'5000'),
('0004', 'Basu', 'Bombay', '400056', 'Maharashtra', '0'),
('0005', 'Ravi', 'Delhi', '100001', ' ','2000'),
('0006', 'Rukmini', 'Bombay', '400050', 'Maharashtra', '0')
;
TABLE IS UPDATED

ii.
SYNTAX
INSERT INTO Product_master(Product_no, Description, Profit_percent,
Unit_measure, Qty_on_hand, Reoder_lvl, Sell_price, Cost_price)
VALUES ('P00001', '1.44floppies', '5', 'piece', '100', '20', '525', '500'),
('P03453', 'Monitors', '6', 'piece', '10', '3', '12000', '11200'),
('P06734', 'Mouse', '5', 'piece', '20', '5', '1050', '500'),
('P07865', '1.22 floppies', '5', 'piece', '100', '20', '525', '500'),
('P07868', 'Keyboards', '2', 'piece', '10', '3', '3150', '3050'),
('P07885', 'CD Drive', '2.5', 'piece', '10', '3', '5250', '5100'),
('P07965', '540 HDD', '4', 'piece', '10', '3', '8400', '8000'),
('P07975', '1.44 Drive', '5', 'piece', '10','3', '1050', '1000'),
('P08865', '1.22 Drive', '5', 'piece', '2', '3', '1050', '1000'
);

TABLE IS UPDATED
Question 3
On the basis of above two tables answer the following Questionaries:
i. Find out the names of all the clients.

Syntax
SELECT Name FROM [Client_master]

ii. Retrieve the list of names and cities of all the clients.
Syntax
SELECT Name, City FROM [Client_master]
iii. List the various products available from the product_master table.

Syntax
SELECT Description FROM [Product_master]

iv. List all the clients who are located in Bombay.

Syntax
SELECT Name FROM [Client_master] WHERE City='Bombay';
v. Display the information for client no 0001 and 0002.

Syntax
SELECT * FROM [Client_master] WHERE Client_no='0001' OR
Client_no='0002';

vi. Find the products with description as ‘1.44 drive’ and ‘1.22 Drive’.

Syntax
SELECT * FROM [Product_master] WHERE Description='1.44
Drive' OR Description='1.22 Drive';
vii. Find all the products whose sell price is greater then 5000.

Syntax
SELECT * FROM [Product_master] WHERE Sell_Price> '5000';

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

Syntax
SELECT * FROM [Client_master] WHERE City='Bombay' OR
City='Delhi'OR City='Madras';
ix. Find the product whose selling price is greater than 2000 and less than or
equal to 5000.

Syntax
SELECT * FROM [Product_master] WHERE Sell_Price> '2000' AND
Sell_price<= '5000';

x. List the name, city and state of clients not in the state of ‘Maharashtra’.

Syntax
SELECT Name, City, State FROM [Client_master] WHERE NOT
State='Maharashtra';
Assignment 4
Question 1
Create table EMP
i. EMP
SYNTAX
CREATE TABLE EMP
(
EMPNO int not null,
ENAME varchar2(10),
JOB varchar2(9),
MGR int,
HIREDATE DATE,
SAL int,
COMM int,
DEPTNO int
);

ii. Enter Data


SYNTAX
insert into
EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO)
values(7369,’SMITH’,’CLERK’,7902, ‘17-DEC-80’,800,20);

INSERT INTO EMP


VALUES(7499,’ALLEN’,’SALESMAN’, 7698, ‘20-FEB-81’,1600, 300,30),
(7521, ‘WARD’, ‘SALESMAN’, 7698, ‘22-FEB-81’, ‘1250’,500, 30);

insert into
EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values
(7566, ‘JONES’, ‘MANAGER’, 7839, ‘02-APR-81’, 2975, 20);
Insert into EMP values
(7654, ‘MARTIN’, ‘SALESMAN’, 7698, ‘28-SEP-81’, 1250,1400,30);

Insert into
EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values
(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);
insert into
EMP(EMPNO,ENAME,JOB,HIREDATE,SAL,DEPTNO)values
(7839, ‘KING’, ‘PRESIDENT’, ‘17-NOV-81’, 5000,10);

INSERT INTO EMP VALUES


(7844, ‘TURNER’, ‘SALESMAN’, 7698, ‘08-SEP-81’, 1500,0,30);
insert into
EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values
(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);

i. Retrieve a list of MANAGERS.

SYNTAX
SELECT * FROM EMP WHERE JOB=’MANAGER’
ii. Find out salary of both MILLER and SMITH.
SYNTAX
SELECT * FROM EMP WHERE ENAME=’SMITH’ OR ENAME=’MILLER’;

iii. Find out the names and salaries of all employees earning more than 1000 per
month.,
SYNTAX
SELECT ENAME, SAL FROM EMP WHERE SAL>1000;
iv. Display the names and salaries of all employees except JAMES.
SYNTAX
SELECT ENAME, SAL FROM EMP WHERE NOT ENAME=’JAMES’;

v. 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.
SYNTAX
SELECT ENAME, SAL FROM EMP WHERE
SAL>1500 AND DEPTNO=’10’ OR DEPTNO=’30’;
vi. List the name and salary for all employees whose salary is not in the
range of 1500 and 2850.
SYNTAX
SELECT * FROM EMP WHERE NOT SAL>1500 OR
SAL<2850;

vii. 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.
SYNTAX
SELECT ENAME, JOB,SAL
FROM EMP
WHERE JOB IN (‘ANALYST’, ‘CLERK’)
AND SAL NOT IN (1000,3000,5000);
Or
SELECT ENAME, JOB, SAL FROM EMP WHERE SAL
not in(1000,3000,5000) AND (JOB = ‘CLERK’ OR JOB
=’ANALYST’);

viii. Display the name, salary and commission for all employees whose
commission amount is greater than their salary increased by 10%.
(100+10=110%)
SYNTAX
SELECT ename , sal , comm FROM emp WHERE comm > sal * 1.1;
Or
SELECT ENAME, SAL, COMM FROM EMP WHERE
(COMM/SAL) >= 0.10;

ix. Display the name of all employees who have two Ls in their name
and are in department 30 or their manager is 7782.,
SYNTAX
SELECT ename FROM emp WHERE ename like
‘%L%L%’ AND deptno = 30 OR mgr = 7782;
x. Find out the details of employees whose names begin with ‘S’.
SYNTAX
SELECT ename FROM emp WHERE ename like ‘S%’;

xi. Find out the names of all employees that have ‘A’ anywhere in their
name.
SYNTAX
SELECT ename FROM emp WHERE ename lik ‘%A%’;
xii. Find out the names of all employees that have ‘L’ as their third
character in their name.
SYNTAX
SELECT ename FROM emp WHERE ename like ‘__A%’;

xiii. Find out the names of the employees whose name begin with ‘A’ or
‘M’.
SYNTAX
SELECT ename FROM emp WHERE ename like ‘A%’
OR ENAME LIKE ‘M%’;
xiv. List all the employees whose commission is NULL.
SYNTAX
SELECT ename FROM emp WHERE COMM IS NULL;

xv. List employee number, employee name, total salary


(i.e. salary + commission). (Note: Manipulate the
NULL values accordingly.)

SYNTAX
select empno, Ename, IFNULL(sal,0)+ IFNULL(comm,0)
as Total_salary from emp;
xvi. List the name of the employee and designation of the employee, who
does not report to anybody.
SYNTAX
select Ename,JOB from emp WHERE MGR IS NULL;

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

SYNTAX
SELECT ename,
12*sal Yearly_Salary
FROM emp
ORDER BY Yearly_Salary DESC;
xviii. Retrieve the names of departments in ascending order and their
employees in descending order.

SYNTAX
SELECT empno, ename, deptno
FROM emp
ORDER BY DEPTNO ASC, ename DESC;

xix. Select the name, job, salary, and department number of all
employees except SALESMAN from department number 30.
SYNTAX
SELECT ENAME, JOB, SAL, DEPTNO FROM EMP
WHERE JOB <> ‘SALESMAN’ AND DEPTNO = ‘30’;

xx. List different jobs with no duplicates.

SYNTAX
SELECT DISTINCT JOB FROM EMP;

xxi. Count the total number of employees.

SYNTAX
SELECT * FROM EMP WHERE SAL>1000;
xxii. Print the total employees and average salary of each
department.

SYNTAX
SELECT * FROM EMP WHERE SAL>1000;

xxiii. Select the minimum and maximum salary from EMP


table.

SYNTAX
SELECT * FROM EMP WHERE SAL>1000;

xxiv. List the minimum and maximum salaries of each


department.

SYNTAX
SELECT * FROM EMP WHERE SAL>1000;

xxv. List all departments in which more than 3 employees


are working.

SYNTAX
SELECT * FROM EMP WHERE SAL>1000;
Assignment 5
Q. What is ER Model? Explain Entity, Attribute, and relation with their types and shapes.
ER model stands for an Entity-Relationship model. It is a high-level data model. This model is used to define
the data elements and relationship for a specified system. It develops a conceptual design for the database. It
also develops a very simple and easy to design view of data. In ER modeling, the database structure is
portrayed as a diagram called an entity-relationship diagram.

For example, Suppose we design a school database. In this database, the student will be an entity with
attributes like address, name, id, age, etc. The address can be another entity with attributes like city, street
name, pin code, etc and there will be a relationship between them.

● Components of ER Diagram
1. Entity
An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as
rectangles. Consider an organization as an example- manager, product, employee, department etc. can
be taken as an entity.

a. Weak Entity

An entity that depends on another entity called a weak entity. The weak entity
doesn't contain any key attribute of its own. The weak entity is represented by a
double rectangle.

2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an
attribute.

For example, id, age, contact number, name, etc. can be attributes of a student.

a. Key Attribute
The key attribute is used to represent the main characteristics of an entity. It
represents a primary key. The key attribute is represented by an ellipse with the text
underlined.

b. Composite Attribute
An attribute that composed of many other attributes is known as a composite
attribute. The composite attribute is represented by an ellipse, and those ellipses are
connected with an ellipse.

c. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a
multivalued attribute. The double oval is used to represent multivalued attribute.
For example, a student can have more than one phone number.

d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It
can be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another
attribute like Date of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used to
represent the relationship.

Types of relationship are as follows:

a. One-to-One Relationship
When only one instance of an entity is associated with the relationship, then it is known
as one to one relationship.
For example, A female can marry to one male, and a male can marry to one female.

b. One-to-Many Relationship
When only one instance of the entity on the left, and more than one instance of an entity
on the right associates with the relationship then this is known as a one-to-many
relationship.
For example, Scientist can invent many inventions, but the invention is done by the only
specific scientist.
c. Many-to-One Relationship
When more than one instance of the entity on the left, and only one instance of an entity
on the right associates with the relationship then it is known as a many-to-one
relationship.
For example, Student enrolls for only one course, but a course can have many students.

d. Many-to-Many Relationship
When more than one instance of the entity on the left, and more than one instance of an
entity on the right associates with the relationship then it is known as a many-to-many
relationship.
For example, Employee can assign by many projects and project can have many
employees.
Assignment 6

Q. Draw an ER Diagram and Relational Schema for an e-commerce site that sells the product online.
Assignment 7
Q. Draw an ER Model and Relational Schema for a Hospital Management System.
Assignment 8
Q. Draw an ER Model and Relational Schema for a University Management System.
Assignment 9
Create a table named as STUDENT with the following fields as:
• S_no
• NAME
• CITY
• AGE
• MARKS

SYNTAX

CREATE TABLE Student


(
S_no int,
NAME varchar(255),
CITY varchar(255),
AGE int,
MARKS int
);
Execute the following queries after entering 10 records in the table.

SYNTAX
INSERT INTO STUDENT (S_no, NAME, CITY, AGE, MARKS)
VALUES ('1','Liam','Agra','14','75'),
('2','Adarsh','Delhi','16','80'),
('3','Olivia','Chandigarh','18','95'),
('4','Aakesh','Delhi','15','90'),
('5','Ava','Kolkata','14','70'),
('6','Lavanya','Mumbai','17','65'),
('7','Charlotte','Chennai','15','98'),
('8','Bhavna ','Delhi','16','50'),
('9','Layla','Pune','17','99'),
('10','Tom','Delhi','18','59');

• Display all the details of the given table

SYNTAX

SELECT * FROM [Student]


• Display the names in alphabetical order
SYNTAX
SELECT NAME FROM [Student] ORDER BY NAME;

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

SYNTAX

SELECT NAME, MARKS FROM [Student] WHERE MARKS>60;


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

SYNTAX

SELECT NAME FROM [Student] WHERE NAME LIKE 'A%';

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

SYNTAX

SELECT * FROM [Student] WHERE CITY= 'Delhi';


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

SYNTAX

SELECT * FROM [Student] WHERE AGE> '15';

• Display the S_no of those students whose names starts with L and ends with A or marks

less than 70

SYNTAX

SELECT S_no FROM [Student] WHERE NAME LIKE 'L%A' AND MARKS<'70';
• Display the name and S_no of those students who have scored marks equal to 95

SYNTAX

SELECT S_no FROM [Student] WHERE MARKS= '95';

• Display the names and marks of all those students who have scored marks between 75

and 90.

SYNTAX

SELECT NAME, MARKS FROM [Student] WHERE MARKS> '70' OR MARKS< '90';
Assignment 10
Assignment on Aggregate and grouping Functions

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


Deptno.
SYNTAX
CREATE TABLE employee
(
empno int,
ename varchar(255) Not Null ,
salary int Not Null,
Commission int,
Job varchar(255),
Deptno int
);
Perform the following operations:

1. Insert 5 records in employee table


SYNTAX
INSERT INTO employee (empno, ename, salary, Commission, Job, Deptno)
VALUES ('1','Liam','40000','2000','manager','10'),
('2','Adarsh', '37000', '6000','accountant','5'),
('3','Olivia','50000','3400','manager', '9'),
('4','Aakesh', '65000', '6200','copywriter','10'),
('5','Ava','75000','4000','advertising executive','12');

2. Find average and total salaries of all employee


SYNTAX
SELECT AVG (salary), sum (salary) FROM [employee]

3. Find average and total salaries of each employee


SYNTAX
SELECT ename , AVG (salary), sum (salary) FROM [employee] group by ename

4. Find minimum salary of Manager


SYNTAX
SELECT min(salary) FROM [employee]
5. Find the maximum salary of the Manager
SYNTAX
SELECT max(salary) FROM [employee]

6. How many employees are Managers


SYNTAX
SELECT count(empno) FROM [employee] where job = 'manager';

7. Add 50% salary to salary column and name it HRA


SYNTAX
SELECT salary + (salary * 50/100) as HRA
From employee
8. Count the total no. employees
SYNTAX
SELECT count(empno) FROM [employee]

9. Count the no. of departments available


SYNTAX
SELECT count(deptno) FROM [employee]

10. Count the no. of employees in each department


SYNTAX
SELECT deptno, count(empno) FROM [employee] group by deptno

11. Update the commission to 10%of salary for all the employees having salary greater
than 50000
SYNTAX
update employee
set commission= salary* .1
where salary>50000 ;

12. Find the name of lowest paid employee for each manager
SYNTAX
SELECT ename, min(salary) FROM [employee] where job= 'manager';
13. Update the salaries of all employees in department 10 by hiking it by 15%.
SYNTAX
update employee
set salary= salary+(salary*.15)
where deptno='10' ;

14. Find the difference between highest and lowest salaries for each dept
SYNTAX
SELECT MAX(salary) - MIN(salary) DIFFERENCE
FROM employee;
15. List average salary for all the depts which have more than 2 People
SYNTAX
SELECT deptno, AVG(salary), COUNT(*)
FROM employee
GROUP BY Deptno
HAVING COUNT(*) > 2;

16. List jobs of all the employees where maximum salary is more than 40000
SYNTAX
SELECT job
FROM employee where salary> '40000';
17. List jobs and no. of employees in each job
SYNTAX
SELECT job, count(empno)
FROM employee
GROUP BY job;

18. List average salary of each job excluding managers


SYNTAX
SELECT job, AVG(salary)
FROM employee
where job<> 'manager'
GROUP BY job;

19. List total, Max, Min, Average salary of employees job wise
SYNTAX
SELECT job, SUM(salary), AVG(salary), MAX(salary), MIN(salary)
FROM employee
GROUP BY job;
Assignment 11
Create a table Student with following fields
• Enrolment_no
• S_name
• Course_id
• Batch
• Semester
SYNTAX
CREATE TABLE Student
(Enrolment_no int,
S_name varchar(255),
Course_id int,
Batch int,
Semester int
);
SYNTAX
INSERT INTO student (Enrolment_no, S_name, Course_id, Batch, Semester)
VALUES ('101','Liam','17','2017-20','6'),
('102','Sadarsh', '21','2018-21','5'),
('301','Olivia','44','2017-20', '6'),
('342','Seema','18','2019-22', '4'),
('101','Sakshi','15','2017-20', '6'),
('356','Joel','44','2020-23', '2'),
('253','Ayushi','17','2017-20', '6'),
('103','Harsh','21','2018-21', '5'),
('432','Natasha','44','2019-22','4'),
('101','Sangharsh','15','2019-22','4');
Execute the following queries after entering 10 records in the table.
• Display the list of Students in batch ‘2017-2020’

SYNTAX
SELECT * FROM [Student] where batch= '2017-20';

• Display the Enrolment_no of fourth semester students.


SYNTAX
SELECT enrolment_no FROM [Student] where Semester= '4';
• Display the list of students of batch ‘2017-2020’ and course_id is 17.
SYNTAX
SELECT * FROM [Student] where batch= '2017-20' and course_id= '17';

• Display the number of students in course_id 44.


SYNTAX
SELECT count(s_name) FROM [Student] where course_id= '44';
Assignment 12
Create table course with following fields
• Course_id
• S_name
• Course_name
• Batch
• Duration

SYNTAX
CREATE TABLE Course
(Course_id int,
S_name varchar,
Course_name varchar(255),
Batch text,
Duration int
);

SYNTAX
INSERT INTO course(Course_id, S_name, Course_name, batch, Duration)
VALUES ('17', 'Sadarsh', 'BBA', '2017-20', '3'),
('21', 'Olivia', 'B_ed', '2019-21','2'),
('44', 'Seema','Mass_Comm', '2018-20','2'),
('18', 'Sakshi','BBA', '2017-20','3'),
('15', 'Joel','Mass_Comm', '2018-21','3'),
('44', 'Ayushi','B_ed', '2019-21', '2'),
('17', 'Harsh','BBA', '2017-20', '3'),
('21', 'Natasha','BBA', '2017-20', '3'),
('44','Sangharsh', 'B_ed', '2019-23','4'),
('15','Harmoine', 'BBA', '2020-23','3');

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.

SYNTAX
ALTER TABLE student
ADD FOREIGN KEY (Course_id) REFERENCES Course(Course_id);

• Display all students enrolled in BBA course.

SYNTAX
SELECT * FROM [Course] WHERE COURSE_NAME='BBA';
• Display name of students enrolled in 2 year course.
SYNTAX
select S_name from course where Duration='2'

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

SYNTAX
SELECT * FROM [Course] WHERE COURSE_NAME='BBA' and batch= '2017-20';
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

SYNTAX
CREATE TABLE Customer
(
Customer_ID int,
Customer_Name Text,
Designation Text,
City Text,
Country Text,
Phone int
);

SYNTAX
INSERT INTO customer (Customer_ID, Customer_Name, Designation, City, Country,
Phone)
VALUES ('101','Liam','HR','MINSK','BELARUS','1002541294'),
('102','Sadarsh', 'PRODUCTION', 'Kolkata','West Bengal','2805522398'),
('301','Olivia','ACCOUNTING','CANBERRA',' Australia', '9052285'),
('342','Seema','SALES REPRESENTATIVE','OTTAWA','Canada', '190899'),
('101','Sakshi','OWNER','SANTIAGO','CHILE', '70596'),
('356','Victoria','PRODUCTION','STOCKHOLM','SWEDEN', '95191'),
('253','Ayushi','MARKETING','MANILA','PHILIPPINES', '81000'),
('103','Harsh','PRODUCTION','AMSTERDAM','NETHERLANDS', '241090'),
('432','Natasha', 'IT', 'MEXICO CITY','MEXICO','101295'),
('101','Sangharsh','HR','PORT LOUIS','MAURITIUS','120199');

Insert the data into table Customer. And apply the queries:

• Display customer details having designation Sales Representative

SYNTAX
SELECT * FROM [Customer] where designation='SALES REPRESENTATIVE';

• Retrieve customer who is living in Canada


SYNTAX
SELECT * FROM [Customer] where country='Canada';
• Show details of the customer whose name is Victoria
SYNTAX
SELECT * FROM [Customer] where customer_name='Victoria';

• Show detail of the customer who lives in Sweden.


SYNTAX
SELECT * FROM [Customer] where country='SWEDEN';
• Show detail of the customer who is owner.
SYNTAX
SELECT * FROM [Customer] where Designation='OWNER';
Assignment 14
Create a table EMPLOYEE either the following fields:
• Emp_id
• Emp_name
• Dept_name
• Salary
• Address
• Date_of_joining

SYNTAX
CREATE TABLE EMPLOYEE
(
Emp_id int,
Emp_name Text,
Dept_name Text,
Salary int,
Address Text,
Date_of_joining int
);
SYNTAX
INSERT INTO employee (Emp_id, Emp_name, Dept_name, Salary, Address,
Date_of_joining)
VALUES ('101','Liam','HR','18000','Sikkim','10/02/94'),
('102','Sadarsh', 'PRODUCTION', '9000','Kolkata','5/05/98'),
('301','Olivia','ACCOUNTING','10000',' Australia', '9/09/85'),
('342','Seema','IT','30000','Bihar', '19/08/99'),
('101','Sakshi','HR','15000','Delhi', '7/05/96'),
('356','Joel','PRODUCTION','10000','Maharashtra', '9/01/91'),
('253','Ayushi','MARKETING','50000','Delhi', '8/10/00'),
('103','Harsh','PRODUCTION','12000','Tamil Nadu', '24/10/90'),
('432','Natasha', 'IT', '26200','Lucknow','10/12/95'),
('101','Sangharsh','HR','24000','Kanyakumari','12/01/99');

Perform the following queries on it.


1. show the records of the employee whose Emp_id is 101
SYNTAX
SELECT * FROM [EMPLOYEE] WHERE Emp_id='101';
2. Display the record of the employees whose Dept_name is HR and salary >10000
SYNTAX
SELECT * FROM [EMPLOYEE] WHERE Dept_name ='HR' and salary >10000;

3. Delete the record of the employee whose name begins with S or salary >10000
SYNTAX
delete FROM [EMPLOYEE] WHERE salary>10000 or Emp_name like's%';

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


PRODUCTION.

SYNTAX
UPDATE [EMPLOYEE] set Dept_name = 'IT' where Dept_name= 'PRODUCTION';

5. Update the record of the employee, set salary to 15000 where Dept_name is
PRODUCTION.

SYNTAX
UPDATE [EMPLOYEE] set salary= '15000' where Dept_name= 'PRODUCTION';
Assignment 15
Create a table employee with the following fields: Emp_id, Emp_name, Contact
no, Gender, Salary, Emp_grade, Designation, Address
SYNTAX
CREATE TABLE EMPLOYEE
(
Emp_id int,
Emp_name Text,
Contact_no int,
Gender Text,
Salary int,
Emp_grade text,
Designation text,
Address text
);
Execute the following queries on the table created:
SYNTAX
INSERT INTO employee (Emp_id, Emp_name, Contact_no, Gender, Salary, Emp_grade,
Designation, Address)
VALUES ('101','aram','98454863011','male','59000','A', 'proction officer', 'rohini'),
('102','supriya', '2312654532', 'female','64000','B', 'marketing manager', 'gaziabad'),
('356','Joel','5635112456','male','10000','B', 'operations', 'noida'),
('253','Ayushi','212365456','female','80000','A','Marketing head', 'lajpat Nagar'),
('103','Harsh','453532362','male','8000','A','Manager', 'MSI C-4 Janakpuri'),
('432','Natasha','25562332', 'female','8620','B','factory manager','pitampura'),
('101','Sangharsh','231354654','male','8400','A','Intern', 'sonipath');

1. Display the details of the employees


SYNTAX
SELECT * FROM [EMPLOYEE]
2. Display the employee id of employee whose name is supriya.
SYNTAX
SELECT emp_id FROM [EMPLOYEE] where emp_name ='supriya';

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


SYNTAX
SELECT emp_name FROM [EMPLOYEE] where contact_no ='98454863011';

4. Display the details of the employee whose address is MSI, C-4, Janakpuri.
SYNTAX
SELECT * FROM [EMPLOYEE] where address= 'MSI C-4 Janakpuri';

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

SYNTAX
SELECT emp_name FROM [EMPLOYEE] where salary > 10000;

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

SYNTAX
UPDATE employee
SET Emp_grade = 'c'
WHERE salary < '10000';
7. Delete the record of the employee whose gender is male and designation is
Manager

SYNTAX
DELETE FROM [EMPLOYEE] WHERE gender='male' and designation='Manager';
Before

After
8. Display the name, designation, and salary of all the employees whose names
begins with A.
SYNTAX
SELECT emp_name, designation, salary FROM [EMPLOYEE] where emp_name like 'A%'

9. Update the employee details; set designation to assistant manger where


designation is trainee.
SYNTAX
UPDATE employee
SET designation='assistant manager' where designation='trainee';
Before

After
10.Display the employee id, name, salary and designation for the employees where
emp_grade is A.
SYNTAX
SELECT emp_id, emp_name, salary, designation from employee where
emp_grade= 'A';

You might also like