Database Systems
Database Systems
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_nam
eWHERE
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;
REVERSE:
The REVERSE() function reverses a string and returns the result.
SELECT REVERSE('SQL Tutorial');
SOURE CODE:
• Insert 5 to 10 rows in a table?
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;
SELECT DISTINCT:
The SELECT DISTINCT statement is used to return only distinct (different)
values.
SELECT DISTINCT column1, column2, ...
FROM table_name;
SOURCE CODE:
• Find the names of sailors who have reserved atleast one boat
• Find the all sailed ofs ailors who have a rating of 10 or have
reserved boated104
• Find the Sailid ‘s of sailors with age over 20 who have not
registered a redboat.
• Find the names of sailors who have reserved a red or green boat.
• Find sailors whose rating is better than some sailor called Krish.
• Find the names of sailors who are older than the oldest sailor
with a rating of 9.5.
EXPERIMENT-3
• Schema Diagram for the rest of the SQL and PLSQL Programs.
Create the fol- lowing 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:
• Display name of the department and name of manager for all the
departments.
• Display the name of each employee who has a dependent with
the same firstname and gender as the employee.
EXPERIMENT-4
• Create the following tables based on the above Schema Diagram
with appropri-ate data types and constraints in addition to the
tables in Experiment 2. DEPT_LOCATIONS (Dnumber,
Dloaction)
PROJECT (Pname, Pnumber,
Plocation, Dnum)WORKS_ON
(ESSN, Pno, Hours)
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:
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 col- umns.
SELECT
column_n
ame(s)
FROM
table_na
me WHERE
conditio
n
GROUP BY
column_name
(s) ORDER
BY
column_name
(s);
SOURCE
CODE:
• List the project number, name and no. Of employees who work
on that projectfor all the projects.
• For each project, list the project name and total hours (by all
employees) spent on that project.
EXPERIMENT-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 ofemployees 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 arefields from one or more real tables in the database.
CREATE VIEW
view_name AS
SELECT column1,
column2, ...
FROM table_name
WHERE condition;
SOURCE CODE:
• List the projects that are controlled by one department from this
view.
• List the managers of the controlling departments for all the projects.
• List the Location of the controlling departments for all the projects.
EXPERIMENT-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 onlyemp_noemp_name and department.
SOURCE CODE:
EXPERIMENT-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
EXPERIMENT-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:
EXPERIMENT-9
• Write a procedure to check whether the given number is
Armstrong or not. AIM: To write a procedure to check whether the
given number is Armstrong or not. DESCRIPTION:
DELIMITER:
Delimiters can be used when you need to define the stored procedures, function as well as
to create triggers.The default delimiter is semicolon. You can change the delimiters to
create procedures and so on. However, but if you are considering multiple statements, then
you need to use different delimiters like $$ or //.
SOURCE CODE:
EXPERIMENT-10
• Write a procedure which accept the account number of a
customer and re-trieve the balance
AIM: To write a procedure which accept the account number of a
customer and re-trieve the balance.
SOURCE CODE:
RESULT: EXECUTED SUCESSFULLY
EXPERIMENT-11
• Write a procedure which accepts the student number and
displays the depart-ment in which he belongs to.
AIM: To write a procedure which accepts the student number and
displays the depart-ment in which he belongs to.
SOURCE CODE:
RESULT: EXECUTED SUCESSFULLY
EXPERIMENT-12
• Create a cursor to modify the salary of all employees belonging to
'Research' de-partment by 150%.
AIM: To create a cursor to modify the salary of all employees belonging to
'Research'department by 150%.
DESCRIPTION:
CURSOR:
Cursor is a Temporary Memory or Temporary Work Station. It is
Allocated by Database Server at the Time of Performing DML (Data
Manipulation Language) operations on Table by User. Cursors are used
to store Database Tables. There are 2 types of Cursors: Implicit Cursors,
and Explicit Cursors. These are explained as following below.
Implicit Cursors:
Implicit Cursors are also known as Default Cursors of SQL SERVER.
These Cursorsare allocated by SQL SERVER when the user performs
DML operations.
Explicit Cursors:
Explicit Cursors are Created by Users whenever the user requires them.
Explicit Cur-sors are used for Fetching data from Table in Row-By-
Row Manner.
Declare Cursor Object.
EXPERIMENT-13
• Consider the college database. Retrieve all students who have
registered for aspecific course and store their details into another
table using Cursors.
AIM: To retrieve all students who have registered for a specific course
and store theirdetails into another table using Cursors.
SOUREC CODE:
EXPERIMENT-14
• Write an update trigger on Account table. The system should
keep track of therecords that are being updated.
AIM: To update trigger on Account table. The system should keep track
of the records that are being updated.
DESCRIPTION:
TRIGGER:
Trigger: A trigger is a stored procedure in database which automatically
invokes when- ever a special event in the database occurs. For example, a
trigger can be invoked when a row is inserted into a specified table or
when certain table columns are being updated. Syntax:
create trigger
[trigger
_name][before
| after]
{insert |
update |
delete}on
[table
_name]
[for
each
row]
[trig
ger
_bo
dy]
SO
UR
CE
CO
DE:
To Drop database:
{dropped: “database_name”, ”ok”,:1}
RESULT: EXECUTED SUCESSFULLY
V
I
V
A
V
O
I
C
E
• Define Database.
A prearranged collection of figures known as data is called database.
• What is DBMS?
Database Management Systems (DBMS) are applications designed
especially whichenable user interaction with other applications.
• What are the various kinds of interactions catered by DBMS?
R
e
t
r
i
e
v
a
l
A
d
m
i
n
i
s
t
r
a
t
i
o
n
• Segregate database technology’s development.
Navigat
ional
model
SQL/
relation
al
model
• Who proposed the relational model?
Edgar F. Codd proposed the relational model in 1970.
• What are the features of Database language?
A database language may also incorporate features like:
DBMS-specific Configuration and management of storage engine
Computations to modification of query results by computations, like
summing, count- ing, averaging, grouping, sorting and cross-referencing
Constraint enforcement Appli-cation programming Interface
• What do database languages do?
As special-purpose
languages, they have:
Data definition
language
Data
manipulation
language
Query
language
• Define database model.
of columns.
Advantages of
normalizing database
are:No duplicate entries
They are:
CREATE:
Temporary views
cannot be created.
Temporary tables cannot
contain views.
INNER JOINs: Blank rows are left in the middle while more
than equal to two ta-bles are joined.
OUTER JOINs: Divided into Left Outer Join and Right Outer
Join. Blank rows are left at the specified side by joining tables in other
side.
• The name of the procedure must be specified after the Create Procedure
keyword
• After the name of the procedure, the list of parameters must be
specified in the pa-renthesis. The parameter list must be comma-
separated
• The SQL Queries and code must be written between BEGIN and END
keywords
C
L
O
S
E
• What is the syntax to create cursor?
Ans.
Declare
cursor _name
cursorSelect
statement;
• How to Fetch the cursor?
Ans. FETCH [ NEXT [ FROM]] cursor _name INTO variable _list;
• Why cursor is used in MYSQL?
Ans. In MySQL, a cursor allows row-by-row processing of the result
sets. A cursor is used for the result set and returned from a query. By
using a cursor, you can iterate, or step through the results of a query and
perform certain operations on each row.
• How many types of cursors in MYSQL?
Ans. There are 2 types of Cursors: Implicit Cursors, and Explicit Cursors.
• What is meant by Implicit cursor?
Ans. Implicit Cursors are also known as Default Cursors of SQL
SERVER. TheseCursors are allocated by SQL SERVER when the
user performs DML operations.
• What is meant by Explicit cursor?
Ans. Explicit Cursors are Created by Users whenever the user requires
them. ExplicitCursors are used for Fetching data from Table in Row-By-
Row Manner.
• What are the advantages of cursors?
Ans.
•They are helpful in performing the row-by-row processing and also
row wise valida-tion on each row.
•Better concurrency control can be achieved by using cursors.
r
o
w
]
[
t
r
i
g
g
e
r
_
b
o
d
y
]
• How many types of Triggers we have?
Ans. There are two types of triggers
• After Triggers (For Triggers)
• Instead Of Triggers
• Explain what is after Trigger?
Ans. Insert, Update, Delete.
• What is the maximum depth level for nested triggers?
Ans. 32 levels.
• What is NoSQL?
NoSQL databases are non-tabular databases which store data
differently than rela- tional databases. The hiring manager may start
your interview question to check yourbasic understanding of data
management. In your answer, you may briefly explain what NoSQL is
and consider sharing some of its unique traits or features
• What are the different NoSQL databases?
There are four different types of NoSQL databases. List all four of
them in your an- swer to show your understanding of the data
management system to the hiring man-ager.
• What is the key value offering in NoSQL?
NoSQL has a few value offerings that differ from other database
management sys- tems. Based on your experience, tell the interviewer
what you feel provides the most value. Try to keep the language as
simple as possible since the interviewer may not be from a technical
background.
• How to increase scalability in NoSQL?
As the company grows, scalability is often a priority. As a team
member, you may search for ways to scale the database and offer
solutions effectively. You can discuss one such solution in your answer
and prove your problem-solving ability to the hiring manager.
• What is a graph database?
As a technical professional, you may work with members outside of
your team. The hiring manager may want to assess your ability to
explain complex terms simply. In your answer, define what a graph
database is and consider talking about its usage.
69: Can NoSQL replace SQL?
A: No, NoSQL cannot replace SQL as certain projects require SQL only.
70: Where is NoSQL used?
A: NoSQL is used by companies that need a distributed data system for
storing and maintaining a large amount of unstructured and structured types
of data.
71: Where is SQL used?