Professional Documents
Culture Documents
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.
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?
LBRCE-AI&DS/A 22761A5433
Pa ge|3
LBRCE-AI&DS/A 22761A5433
Pa ge|4
LBRCE-AI&DS/A 22761A5433
Pa ge|5
k) Display student names padded with * after the name of all students
and beforethe name of all students
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:
e) Find the names of sailors who have reserved atleast one boat
f) Find the all sailed ofs ailors who have a rating of 10 or havereserved
boated104
h) Find the names of sailors who have reserved a red or green boat.
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.
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, ...);
NOT IN:
Lbrce-AI&DS/A 22761A5433
P a g e | 15
Lbrce-AI&DS/A 22761A5433
P a g e | 16
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.
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
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.
h) For each project, list the project name and total hours (by all
employees) spenton that project.
j) Retrieve the names of all employees who do not work on any project.
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.
d) List the Location of the controlling departments for all the projects.
LBRCE-AIDS/A 22761A5433
P a g e | 26
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:
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:
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:
LBRCE-AIDS/A 22761A5433