Database Management System Long

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

DATABASE MANAGEMENT SYSTEM

ASSIGNMENT-2
SUBMITTED TO: Ms. P. Sobha Rani

NAME: BINOD KUMAR SAHU


COURSE: IMBA 2ND YEAR (4TH
TRIMESTER)
ROLL NO: 1234110107

Q1) Write down any 15 select syntaxes and explain why


we use a select syntax
Ans) The SELECT statement is used to select data from a
database. The result is stored in a result table, called the

result-set.
SELECT * FROM table_name
1) Select <Column_name> from <table_name>;
2) Select <Column_name> from <table_name> where
<condition>;
3) Select <Column_name> from <table_name> where
<condition>
like <pattern>;
4) Select <Column_name> from <table_name> where
<condition> order by <expression>;
5) Select <Column_name> from <table_name> where
<condition> group by <expression>;
6) Select <Column_name> from <table_name> where
<condition> having <expression>;
7) Select <Column_name1> from <table_name1> Minus
Select <Column_name2> from <table_name2> ;
8) Select <Column_name1> from <table_name1> Intersect
Select <Column_name2> from <table_name2> ;
9) Select <Column_name1> from <table_name1> Union
Select <Column_name2> from <table_name2> ;

10) Select <Column_name1> from <table_name1> Union All


Select <Column_name2> from <table_name2> ;

Q2) . Define SQL, and write down the SQL


statements with example.
Ans)

SQL stands for Structured Query Language


SQL lets you access and manipulate databases

SQL is an ANSI (American National


Institute) standard
1) Select Statement
2) Delete Statement:- DELETE FROM table_name
WHERE
some_column=some_value

Standards

3) Commit
4) Rollback
5) Alter:- ALTER TABLE table_name
RENAME TO new_table_name
6) Update:- UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
7) Modify:- Alter TABLE "table_name"
ALTER COLUMN "column 1" "New Data Type
8) Union:- SELECT Date FROM Store_Information
UNION
SELECT Date FROM Internet_Sales
9) Union All:- SELECT Date FROM Store_Information
UNION ALL
SELECT Date FROM Internet_Sales

10)
Intersect:- SELECT Date FROM Store_Information
Intersect SELECT Date
FROM Internet_Sales
11) Minus:- SELECT Date FROM Store_Information
Minus
SELECT Date FROM Internet_Sales
12) Where
13) Like

Q3) Define Trigger, types of Trigger .syntax of


triggers with examples
Triggers
Ans) Triggers are named database objects that are implicitly fired
when a triggering event occurs. The trigger action can be run
before or after the triggering event. Triggers are similar to stored
procedures but differ in the way that they are invoked.
Support for triggers in MySQL is only included beginning with
release 5.0.2. A trigger can only be associated with a table and
defined to fire when an INSERT, DELETE or UPDATE statement is
performed on the table. MySQL does not permit two triggers with
the same trigger timing (BEFORE or AFTER) and trigger event or
statement (INSERT, DELETE, or UPDATE) to be defined on a table.
For example, you cannot define two BEFORE INSERT or two AFTER
UPDATE triggers for a table. All triggers defined on MySQL are row
triggers, which mean that the action defined for the triggers is
executed for each row affected by the triggering statement.
Error handling during trigger execution for transactional tables
ensures that either both the triggering statement and trigger
action is completed successfully or neither the trigger statement

nor the trigger action is executed, that is all changes made are
rollback on failure. For non-transactional tables, all changes made
prior to the point of error remains in effect.
Types of Triggers in Oracle
1. Before Trigger
2. After Trigger
3. Row level trigger
4. Schema Trigger
5. Instead of Trigger
6. Database Trigger
7. Statement level Trigger

The following is the syntax to create a trigger


CREATE TRIGGER <trigger name>
{ BEFORE | AFTER }
{ INSERT | UPDATE | DELETE }
ON <table name>
FOR EACH ROW
<triggered action>
In Oracle, triggers can be fired when one of the following
operations occurs:

DML statements (INSERT, DELETE or UPDATE) that modify


data on a table or view
DDL statements

User events such as logon and logoff

System events such as startup, shutdown, and error


messages

Oracle allows multiple triggers with the same trigger timing and
trigger event to be defined on a table; however, these triggers are
not guaranteed to execute in any specific order. Triggers can be
defined as row triggers or statement triggers. Statement triggers
are fired once for each triggering statement regardless of the
number of rows in a table affected by the triggering statement.
For example if a DELETE statement deletes several rows from a
table, a statement trigger is only fired once.
The execution model for Oracle triggers is transactional. All
actions performed as a result of the triggering statement,
including the actions performed by fired triggers, must all
succeed; otherwise, they are rolled back.

Q4) Define procedure, syntax of procedure and


difference between procedure and stored
procedure.
Ans) A procedure is a subprogram that performs a specific action.
You must declare and define a procedure before invoking it. You
can either declare or define it at the same time, or you can
declare it first and then define it later in the same block or
subprogram.
Syntax
Procedure declaration: =

Procedure heading: =

Procedure definition: =

Keyword and Parameter Descriptions


Body
The required executable part of the procedure and, optionally, the
exception-handling part of the procedure.
Declare section
The optional declarative part of the procedure. Declarations are
local to the procedure, can be referenced in body, and cease to
exist when the procedure completes execution.
Procedure declaration
Declares a procedure, but does not define it. The definition must
appear later in the same block or subprogram as the declaration.
A procedure declaration is also called a procedure specification, or
procedure spec.
Procedure definition
Either defines a procedure that was declared earlier in the same
block or subprogram, or declares and defines a procedure.
Procedure name
The name that you give to the procedure that you are declaring or
defining.

Stored Procedures
Stored procedures provide a powerful way to code application
logic that can be stored on the server. MySQL and Oracle both use
stored procedures and functions. Stored functions are similar to
procedures, except that a function returns a value to the
environment in which it is called. In MySQL, stored procedures
and functions are collectively called routines.
The following sections compare stored procedures in MySQL and
Oracle:

Individual SQL Statement


Variables in stored Procedures

Error Handling in Stored Procedures

3.2.1 Individual SQL Statements


This section describes considerations related to the following
statements or constructs:

REPLACE Statement
DO Statement

Compound DECLARE Statement

Compound SET Statement

3.2.1.1 REPLACE Statement


The REPLACE statement in MySQL is a dual-purpose statement. It
works like the INSERT statement when there is no record in the
table that has the same value as the new record for a primary key
or a unique index, and otherwise it works like the UPDATE
statement.
Oracle does not have any built-in SQL statements that supports
the purposes of the MySQL REPLACE statement. To convert this
statement to Oracle, an emulated function using both the INSERT
and UPDATE statements has to be created. An attempt is first

made to place the data into the table using the INSERT statement;
and if this fails, the data in the table is then updated using the
UPDATE statement.
DO Statement
As its name implies, the DO statement in MySQL does something
but does not return anything; specifically, it executes the commadelimited list of expressions specified as its parameters. The DO
statement is converted to a SELECT expr1 [, expr2,] INTO
FROM DUAL statement in Oracle.
Compound DECLARE Statement
MySQL uses the DECLARE statement to declare local variables in
stored procedures. PL/SQL does not allow multiple declarations;
each declaration must be made separately. To convert compound
DECLARE statements into functionally equivalent PL/SQL code,
each MySQL multiple declaration statement should be converted
into logically equivalent separate statements, one for each
declaration.
For example, consider the following MySQL simple declaration and
multiple declaration statements:
/* Simple declaration */
DECLARE a INT;
/* Compound declaration */
DECLARE a, b INT DEFAULT 5;
The PL/SQL functionally equivalent statements are:
/* Simple declaration */
a INT;
/* Multiple declarations */
a INT := 5;
b INT := 5;

Q5) Define the following term


1)

Concurrency Control

Definition
Concurrency control is a database management systems (DBMS)
concept that is used to address conflicts with the simultaneous
accessing or altering of data that can occur with a multi-user
system. Concurrency control, when applied to a DBMS, is meant
to coordinate simultaneous transactions while preserving data
integrity. [1] The Concurrency is about to control the multiuser
access of Database
Illustrative Example
To illustrate the concept of concurrency control, consider two
travellers who go to electronic railway reservation counter at the
same time to purchase a train ticket to the same destination on
the same train. There's only one seat left in the coach, but
without concurrency control, it's possible that both travelers will
end up purchasing a ticket for that one seat. However, with
concurrency control, the database wouldn't allow this to happen.
Both travellers would still be able to access the train seating
database, but concurrency control would preserve data accuracy
and allow only one traveler to purchase the seat.
This example also illustrates the importance of addressing this
issue in a multi-user database. Obviously, one could quickly run
into problems with the inaccurate data that can result from
several transactions occurring simultaneously and writing over
each other. The following section provides strategies for
implementing concurrency control.

i)

Transaction processing

A type of computer processing in which the computer responds


immediately to user requests. Each request is considered to be a
transaction. Automatic teller machines for banks are an example
of transaction processing.
The opposite of transaction processing is batch processing, in
which a batch of requests is stored and then executed all at one
time. Transaction processing requires interaction with a user,
whereas batch processing can take place without a user being
present.

ii)

Optimization

The maximizing or minimizing of a given function possibly subject


to some type of constraints.
Broadly, the efforts and processes of making a decision, a design,
or a system as perfect, effective, or functional as possible.
Narrowly, the specific methodology, techniques, and procedures
used to decide on the one specific solution in a defined set of
possible alternatives that will best satisfy a selected criterion. Also
known as system optimization.

An act, process, or methodology of making something (as a


design, system, or decision) as fully perfect, functional, or
effective as possible; specifically: the mathematical procedures
(as finding the maximum of a function) involved in this

You might also like