You are on page 1of 29

Pa ge|1

EXPERIMENT-1
1) Create a table STUDENT with appropriate data types and perform the follow-ing
queries. Attributes are Roll number, student name, date of birth, branch and year of
study
AIM: To Create a table STUDENT with appropriate data types and perform the following queries.
DESCRIPTION:
CREATE:
CREATE TABLE table_name(
column1 datatype,column2 datatype,. ...... );

INSERT:
INSERT INTO table_name
VALUES (value1, value2, value3, ..... );
SELECT:
SELECT column1, column2, ...
FROM table_name;

UPDATE:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

DELETE:
DELETE FROM table_name WHERE condition;

LIKE:
The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column.

SELECT column1, column2, ...


FROM table_name
WHERE columnN LIKE pattern;

LBRCE-AI&DS/A 22761A5433
Pa ge|2

REVERSE:
The REVERSE() function reverses a string and returns the result.
SELECT REVERSE('SQL Tutorial');

SOURE CODE:
a) Insert 5 to 10 rows in a table?

b) List all the students of all branches

LBRCE-AI&DS/A 22761A5433
Pa ge|3

c) List student names whose name starts with ‘s ‘

d) List student names whose name contains ‘s as third literal

e) List student names whose contains two ‘s ‘anywhere in the name

f) List students whose branch is NULL

LBRCE-AI&DS/A 22761A5433
Pa ge|4

g) List students of AIDS & ECE who born after 1980

h) List all students in reverse order of their names

i) Delete students of any branch whose name starts with ‘s ‘

LBRCE-AI&DS/A 22761A5433
Pa ge|5

j) Update the branch of ECE students to AID

k) Display student names padded with * after the name of all students
and beforethe name of all students

RESULT: EXECUTED SUCESSFULLY

LBRCE-AI&DS/A 22761A5433
Pa ge|6

EXPERIMENT-2
2) Create the following tables based on the above Schema
Diagram with appropriate data types and constraints and
perform the following queries.
SAILORS(Sailid,Sailname,Rating,Age)
RESERVES(Sailid,boatid,Day)
BOATS (Boatid, Boat-name, Color)

AIM: To Create the following tables based on the above Schema Diagram
with appro-priate data types and constraints and perform the following
queries.
DESCRIPTION:
AND:
The AND operator displays a record if all the conditions separated by AND
are TRUE.
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
OR:
The OR operator displays a record if any of the conditions separated by OR
is TRUE.
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
UNION:
The UNION operator is used to combine the result-set of two or more
SELECT state-ments.
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;

LBRCE-AI&DS/A 22761A5433
Pa ge|7

SELECT DISTINCT:
The SELECT DISTINCT statement is used to return only distinct (different)values.
SELECT DISTINCT column1, column2, ...
FROM table_name;

SOURCE CODE:

a) Insert 5 to 10 rows in all tables

Lbrce - AI&DS/A 22761A5433


Pa ge|8

Lbrce - AI&DS/A 22761A5433


Pa ge|9

b) Find the name of sailors who reserved boat number 108.

c) Find the name of sailors who reserved green boat.

d) Find the colors of boats reserved by Krish.

e) Find the names of sailors who have reserved atleast one boat

Lbrce - AI&DS/A 22761A5433


P a g e | 10

f) Find the all sailed ofs ailors who have a rating of 10 or havereserved
boated104

g) Find the Sailid ‘s of sailors with age over 20 who have


notregistereda redboat.

h) Find the names of sailors who have reserved a red or green boat.

Lbrce - AI&DS/A 22761A5433


P a g e | 11

i) Find sailors whose rating is better than some sailor called Prabha.

j) Find the names of sailors who are older than the oldest sailorwith a
rating of 9.5.

RESULT: EXECUTED SUCESSFULLY

Lbrce - AI&DS/A 22761A5433


P a g e | 12

EXPERIMENT-3
3) Schema Diagram for the rest of the SQL and PLSQL Programs.
Create the following tables based on the above Schema Diagram with
appropriate data types and constraints.
EMPLOYEE (Fname, Mname, Lname, SSN, Bdate, Address, Gender,
Salary,SuperSSN,DnO,)
DEPARTMENT (Dnumber, Dname, MgrSSN, Mgrstartdate)
DEPENDENT (ESSN, Dependent_Name,Gender, Bdate,
Relationship)

AIM: To Create the following tables based on the above Schema Diagram
with appropri-ate data types and constraints.
DESCRIPTION:
IN:
The IN command allows you to specify multiple values in a WHERE clause.
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);

Lbrce - AI&DS/A 22761A5433


P a g e | 13

NOT IN:

The NOT operator displays a record if the condition(s) is NOT TRUE.

SELECT column1, column2, ...


FROM table_name
WHERE NOT condition;

a) Insert 5 to 10 rows into all the tables

Lbrce - AI&DS/A 22761A5433


P a g e | 14

b) Display all employees’ names along with their department names.

Lbrce-AI&DS/A 22761A5433
P a g e | 15

c) Display all employees’ names along with their dependent details.

d) Display name and address of all employees who work for


Research department.

e) List the names of all employees with two or more dependents.

Lbrce-AI&DS/A 22761A5433
P a g e | 16

f) List the names of employee who have no dependents

g) List the names of employees who have at least one dependent.

h) List the names of the employees along with names of their


supervisors using aliases.

Lbrce-AI&DS/A 22761A5433
P a g e | 17

i) Display name of the department and name of manager for all thedepartments.

j) Display the name of each employee who has a dependent with the
same first name and gender as the employee.

RESULT: EXECUTED SUCESSFULLY

Lbrce-AI&DS/A 22761A5433
P a g e | 18

EXPERIMENT-4
Create the following tables based on the above Schema Diagram
with appropriate data types and constraints in addition to the tables in
Experiment 2.
DEPT_LOCATIONS (Dnumber, Dloaction)
PROJECT(Pname,Pnumber,P
location, Dnum)
WORKS_ON(ESSN, Pno,
Hours)

AIM: To Create the following tables based on the above Schema Diagramwith
appro-priate data types and constraints and perform the following queries.
DESCRIPTION:
GROUP BY:
The GROUP BY statement is often used with aggregate function (
COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result- set by one or more
columns.
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s)

SOURCE CODE:

Lbrce-AI&DS/A 22761A5433 -
P a g e | 19

a) Insert 5 to 10 rows into all the tables.

Lbrce-AI&DS/A 22761A5433
2276 222
22
P a g e | 20

b) Find the names of the employees who work on all the projects
controlledby the department Research.

Lbrce-AI&DS/A 22761A5433
P a g e | 21

c) List the project number, name and no. Of employees who workon
thatprojectfor all the projects.

d) List the names of all the projects controlled by the


departments departmentwise.

e) Retrieve the names of employees who work on all projects that


prapull works on.

Lbrce - AI&DS/A 22761A5433


P a g e | 22

f) List the project numbers for projects that involve an employee


either as worker or as a manager of the department that controls
the project.

g) List the names of all employees in one department who work


more than 10 hours on one specific project

Lbrce - AI&DS/A 22761A5433


P a g e | 23

h) For each project, list the project name and total hours (by all
employees) spenton that project.

i) Retrieve the names of all employees who work on every project

j) Retrieve the names of all employees who do not work on any project.

RESULT: EXECUTED SUCESSFULLY

Lbrce - AI&DS/A 22761A5433


P a g e | 24

EXPERIMENT-5
5) Create a view that has project name, controlling department name, number of
employees and total hours worked on the project for each project with more than
one employee working on it.
AIM: To create a view that has project name, controlling department name, number of
employees and total hours worked on the project for each project with more than one
employee working on it.

DESCRIPTION:

VIEW:
A view contains rows and columns, just like a real table. The fields in a view are fields
from one or more real tables in the database.
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

SOURCE CODE:

a) List the projects that are controlled by one department from this view.

LBRCE-AIDS/A 22761A5433
P a g e | 25

b) List the managers of the controlling departments for all the projects.

c) Demonstrate one update operation on this view.


A) UPDATION OF VIEW CAN’T BE DONE IF THAT VIEW CONTAINS ANY

PRIMARY OR FOREIGN KEYS.

d) List the Location of the controlling departments for all the projects.

LBRCE-AIDS/A 22761A5433
P a g e | 26

e) Retrieve the data from the view.

RESULT: EXECUTED SUCESSFULLY

LBRCE-AIDS/A 22761A5433
P a g e | 27

EXPERIMENT-6

6) Create a view emp from employee such that it contains only emp_no, emp_name

and department.

AIM: To create a view emp from employee such that it contains only emp_noemp_name

and department.

SOURCE CODE:

RESULT: EXECUTED SUCESSFULLY

LBRCE-AIDS/A 22761A5433
P a g e | 28

EXPERIMENT-7
7) Create a view dept from department with only dept_no and location.
AIM: To create a view dept from department with only dept_no and location.

SOURCE CODE:

RESULT: EXECUTED SUCESSFULLY

LBRCE-AIDS/A 22761A5433
P a g e | 29

EXPERIMENT-8

8) Create a view that contains the details of employees who are managers only AIM:

To create a view that contains the details of employees who are managers only

SOURCE CODE:

RESULT: EXECUTED SUCESSFULLY

LBRCE-AIDS/A 22761A5433

You might also like