0% found this document useful (0 votes)
4 views80 pages

DBMS Lesson

The document provides an overview of Database Management Systems (DBMS), including definitions, advantages, and disadvantages compared to traditional file processing systems. It discusses the three-level architecture of database systems, data abstraction, and various data models, including the relational model. Additionally, it covers normalization techniques, SQL fundamentals, and the advantages of using SQL for database manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views80 pages

DBMS Lesson

The document provides an overview of Database Management Systems (DBMS), including definitions, advantages, and disadvantages compared to traditional file processing systems. It discusses the three-level architecture of database systems, data abstraction, and various data models, including the relational model. Additionally, it covers normalization techniques, SQL fundamentals, and the advantages of using SQL for database manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

DATABASE

MANAGEMENT
SYSTEM
(22319)
Unit 1..Database System Concept

1. Concept of Data,Database,DBMS

DATA:- Data is a information Which has been


translate into a form that is more convenient to
process or move

DATABASE:-The collection of related data is


termed as Database Which is organized in such a
way That it can be Easily retrieved And managed

File processing System:-


-File processing system is a computer based
system in which all the information is stored in
various computer File
-It is useful but As the Requirement of data
processing and the size of data increases the
Drow back of system comes
Advantages Of DBMS over file processing
system
1. Controlling Data redundancy
2. Data consistency
3. Sharing of data
4. Data independence
5. Data control
6. Security
7. Control over concurrency
8. Data Modelling of real Word

Disadvantages of traditional File processing


System
1. Data Redundancy
2. Data inconsistency
3. Limited data sharing
4. Difficulty in accessing data
5. Data dependence
6. Poor data control
7. Problem of security
Application of DBMS
1. Telecom
2. Banking
3. Industry
4. E-commerce
5. Airlines
6. Education System
7. Railway Reservation system
8. Library management System
9. Social Media site

Disadvantages of DBMS
1. Increased Costs
2. Complexity
3. Size
4. Replacement cycle
5. Higher Impact Of a failure
6. Performance
2..Three Level Architecture For Database System

- A data base system is Collection Of related data and


System Software Which Managed the data
- A data is generally Stored in a Detailed and complex
manner
-It is a Important To provide An Abstract View Of Data
to a user

3..Data Abstraction
- Extracting The important data by ignoring the
remaining irrelevant details is known as
Abstraction
- This process of hiding irrelevant details from
user is called as data abstraction
- The Complexity Of database can be hiding from
user by using different level of Abstraction
Different level of Data Abstraction
(Ask in the Exam For 4&2 M )

This Architecture has three level


1. External level
2. Conceptual level
3. Internal level

1. External level
-It is also called as view level .because several users can
view their desired data from this level which is internally
fetched from Database with the help of conceptual and
internal level mapping
2,conceptual level
- It is also called as logical level. The whole design of the
database such as relationship among data, schema of
data.
- Database. Contains and security. Are also implement in
this level of architecture. This level is maintained by
database administrator

3.Internal level
- This level is called as physical level. This level describe how
the data is stored in the strong device.
- This level is also responsible for a locating space to the
data. This is the lowest level of architecture
INSTANCE AND SCHEMA

Instance :- The data is stored in the database at


particular moment. Is called as instance of the
database. (2m)
Schema.:- The design of a database is called as the
schema. (2m)

Types of Schema
1. Physical Schema
2. Logical Schema
3. View Schema

DATA IMPEDANCE

Data Impedance :- The ability to modify schema


definition in one level Without affecting Schema definition in
the next higher level is called data impedance

Types of Data Impedance


1. Physical data impedance
2. Logical data impedance
OVERALL STRUCTURE OF DBMS
(ask in the exam for 4m )

Application End User DDL

DML Compiler DDL


Compiler
Query Optimizer

Stored Data Manager

Data Files Compiled DML Data Dictionary

DDL compiler :- It converts the DDL commands into set of


table containing . Metadata stored in data dictionary.
DML compiler :- It received the DML commands from
application programme and convert DML command into
object code for understanding of database.
Query Optimizer :- It optimise the object code. 2 Execute
query in best way and then send to store data manager.
Storage Data Manager:- It is a programme module
which is responsible for storing. Retrieving and
updating data in Database.
DATABASE COMPONENT
1. DATA Files :- It Store Database itself
2. Compile DML:- The DML compiler. Convert the
high level queries into low level files
, excess commands known as compiled DML
3. Data Dictionary:- It’s store metadata.
Ex- file, storage, access path

Data models.
- The process of analysis of data object and their
relationship to other data object is known as data
modelling.
- It is the. Conceptual representation of data in
database. It is the first step in data base design.

Types of data models.


1. Relational model,
2. Network database model,
3. object oriented data model
4. Hierarchical model.
5. Entity relation model,
6. physical data model.
Relational model/ record based logical model.
- Developed by EF CODD.
- Tables are used and also known as relation.
- Record our known as cupels and fields are known as
attributes.
- Every record must have a unique identification or key.
- Advantages – 1) support SQL
- 2) flexible.
Hierarchical model
- Organise into a tree structure.
- Parent Child relationship.
- Data is stored in the form of record.
- Record is collection of fields and it contains anyone value.
- Advantages. 1) Simple to understand
2) database. Integrity
3) efficient.
Network database model.
- Extent type of. Hierarchical data model. But any child can
have multiple parents.
- No need of parent child relationship. Allows multiple
record link in some files.
- Advantages:-1. Design is simple
2.capability to handle various relationship
3. easy to access.
Entity Relationship model/ ER model
- Represent overall structure of database
- design technique of database
- real world object can be.
- Diagram are used which known as Entity Relationship
Diagram, ER diagrams or Erd’s
- concept of year, model, attribute relationship contains and
key. Object can be.
- Advantage
- Design Simple
- effective representation
- connected with relation model.

Entity And Entity Set


- An entity is a thing that exists either physically or logically.
- An entity is nothing but a thing heaving its oven properties.
- These properties helps to differentiate the object from
other object
- An entity set is a set of entities. We share the same
properties.
Types of entity.
1. Strong entity or regulator entity
If an entity having its own key attributes specified, then it is a
strong entity key. Attribute is used to identify that entity
under quickly among set of entities. In entity set strong
entity is denoted by a single rectangle.

2. Weak entity. The entity TV does not have any key


attribute is known as weak entity. The weak entity has a
partial disCriminator key weak entity depends on the
strong entity for its. Existence Weak entity is denoted
with
the double rectangle.

3. Attribute
- An attribute is a characteristics of an entity
- Entities are represented by means of their attribute.
- All attribute have their own specific values
- Attribute is denoted by an ellipse.
Types of attribute.
1. Single valued attribute,
2. Multivalued attribute,
3. simple attribute,
4. composite attribute,
5. Derived attribute.

1) Single valued attribute.:-A single valued attribute


is the attribute which can hold single value for the single
entity.

2) Multivalued attribute. A multivalued attribute is


the attribute which can hold multiple values for single
entity.

3) Simple attribute.:- An attribute whose value cannot


be further divide is known as simple attribute. That
means it is automatic in nature.
4) Composite attribute:-The composite attributes are
the attributes which can be further divide into sub parts
These subparts represent the basic entities with their.
Indent meaning.

5) Derived attribute:- The attribute. Which is not


physically exist in database but its value can be calculated
from the other present attributes is known as derived
attribute.

6) Key attribute. The key attribute is used to denote


the property that. Unique quickly identifiers and
entity and which is mapped to the primary key field.
In a database.
Relationship
- The associate between 2 different entities is
called as relationship. It is united by diamond.

- Line is used to link attribute to entity and entity


set to relationship sets.

- A unary relationship exit when there is the


relation single entity. A unary relationship is
also known as recursive relationship in which
an entity related with itself

In a
relationship

Person
Binary Relationship :-A Binary relationship Exit only
when there is relation between.only the two entities, in this
case the degree of relation is two

Teacher teaches student

Ternary relationship:- A ternary relationship exit when


there are relation between three entities. Internally
relations the degree of relation is six

Person

Teacher is a student
quaternary relationship:- a quaternary relationship
exit when there are relations between four and kids. In
quaternary relation the degree of relation is Eight

Employee

Teaching is a non teaching


Faculty faculty

Management
Faculty

Mapping. Cardinally in ER diagram.


1. One to one,
2. one to many,
3. menu to menu
4. menu to many
Unit 2) Relational Data Model (18m)
1)Fundamentals Of RDBMS

1. Introduction
The relational model stores data in the form of tables.
This concept is introduced by DR E.F CODD, researcher
of IBM. The relational model is the first choice of.
Commercial data processing application for sharing
the data.

2. Definition
A relational database is collectively combination of
data structure, storage and retrieval operations and
integrity constraints.

3. Advantages of relational model


- Easy of use,
-flexibility,
-security,
-data independence,
-data manipulation language.
4. Characteristics of relational database.

- The data is stored in the tables which are having


relationships in between them.

- Systematic arrangement of data into row and


column. Called as relation or table.

- Table is also form in two dimensional structure.

-Every cell in the relation there is one and only one


value which known as scalar value.

- Column representations attribute and each column


has a Distinct Name.

-All values entered in the columns are of the same


data format.

- it support operation like data definition


manipulation and transaction management.
5 Basic Concept of relational model.
- Tables
-tuple
-attribute
-database,
-domain.

6E.F. Codd’s Rules For RDBMS


Rule 0. foundation rule.
Rule 1. information representation
Rule 2. systematic treatment of null values.
Rule 3. the guaranteed access rule
Rule 4. active online catalogue
Rule 5. The comprehensive Data Sub Language
Rule 6. View Updating rule.
Rule 7. High Level insert, update and delete
Rule 8. physical data independence.
Rule 9. Logical data independence.
Rule 10. Integrity Independence, Reliable Distribution
Independence.
Rule 12. The Non. Sab version rule.
3.Key Concept
- Primary key
- Super key
- candidate key
- Alternate key
- Composite Key
- Foreign Key

4.Normalization

Normalization:- It is a database design technique


which is used to organise the. Table in such a manner
that it should reduce redundancy and dependency of
data.

Types of Normalization.
1. First normal form (1NF)
2. Second normal form,(2NF)
3. Third normal form.(3NF)
First Normal Form.

- First normal form is defined in the definition of


relations itself
- This rule defines that all the attributes in a relation N
must have atomic Domains.
- The value in an atomic domains are Individual unit.

Course Content
Programming Java, c++
Web HTML,PHP,ASP

- We Arrange The Relation As below To Convert it to First


Normal Form.

Course Content
Programming Java
Programming C++
Web Html
Web PHP
Web ASP
- Each attribute must Contain Only A Single Value From
its pre defined Domain
2.7.2 Second Normal Form
• Before we learn about the second normal form, we need to understand the
following:
o Prime attribute: An attribute, which is a part of the
candidate-key, is known as a prime attribute.
o Non-prime attribute: An attribute, which is not a part of the
primary-key, is said to be a non-prime attribute.
• If we follow second normal form, then every non-prime attribute should be
fully functionally dependent on prime key attribute. That is, if X → A
holds, then there should not be any proper subset Y of X, for which Y → A
also holds true.

• We see here in Student_Project relation that the prime key attributes are
Stu_ID and Proj_ID.
• According to the rule, non-key attributes, i.e. Stu_Name and Proj_Name
must be dependent upon both and not on any of the prime key attribute
individually.
• But we find that Stu_Name can be identified by Stu_ID and Proj_Name can
be identified by Proj_ID independently.
• This is called partial dependency, which is not allowed in Second Normal
Form.

• We broke the relation in two as depicted in the above picture. So there exists
no partial dependency.
2.7.3 Third Normal Form
• For a relation to be in Third Normal Form, it must be in Second Normal
form and the following must satisfy:
o No non-prime attribute is transitively dependent on prime
key attribute.
o For any non-trivial functional dependency, X → A, then
either:
▪ X is a super key or, A is prime attribute.

• We find that in the above Student_Detail relation, Stu_ID is the key and
only prime key attribute.
• We find that City can be identified by Stu_ID as well as Zip itself.
• Neither Zip is a super key nor is City a prime attribute.
• Additionally, Stu_ID → Zip → City, so there exists transitive dependency.
• To bring this relation into third normal form, we break the relation into two
relations as follows −
Introduction To SQL

• SQL stands for Structured Query Language


• SQL lets you access and manipulate
databases
• SQL became a standard of the American
National Standards Institute (ANSI) in 1986,
and of the International Organization for
Standardization (ISO) in 1987
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
• SQL can create stored procedures in a
database
• SQL can create views in a database
• SQL can set permissions on tables,
procedures, and views
Advantages Of SQL
1. High Speed
2. Portable
3. Well Defined Standards Exits
4. Supports object based programming
5. Used With All DBMS system with any
vendor
6. No Coding Required
7. Used For Relational Database
8. Easy to learn And understand
9. Complete Language for a database
10. Dynamic database language
11. Can be used as programming and interactive
lang
12. Client/server language
13. Multiple data views
14. Used in internet
Data Types In SQl
1.CHAR(length) 6. DECIMAL Or DEC
2.VARCHAR(length) 7. NUMERIC
3.BOOLEN 8. FLOAT
4.SMALLINT 9. DATE
5.INTEGER Or INT 10. TIME
Component Of SQL
1. Data Definition Languages (DDL)
a) CREATE
b) ALTER
c) DROP
d) RENAME
2. Data Manipulation Language (DML)
a) INSERT
b) UPDATE
c) DELETE
3. Data Control Language (DCL)
a) GRANT
b) REVOKE
4. Transection control language (TCL)
a) BEGIN Transection
b) COMMIT Transection
c) ROLLBACK Transection
5. Data Query language (DQL)
a) SELECT
DDL Commands
Data Integrity Constraint
Types of Data integrity consists
Primary Key
create table emp (eno int ,primary key(eno));

Foreign Key
create table Course_Details (course_id int,course_code
varchar(20)); basic table
create table student2020(stud_id int,name
varchar(20),course_code varchar(20) references
Course_Details(course_code)); reference table

Unique Key
create table student20(stud_id int,name varchar(20),course_code
varchar(20)unique);

business rule consists -Null


NOT NULL
create table Course (course_id int not null,course_code
varchar(20));

CHECK
create table stud1(rno int,sname varchar(20),age int
check(age>=18));
DML Commands
INSERT
1.Inserting values in all column
insert into table_name values (value1,value2,……);
2.Inserting values in specific column
insert into table_name (column1,column2…)values
(value1,value2,……);
3.Inserting records from exesting table into new
table
insert into table_name select column1,column2…
from table_name2 where condition;

UPDATE
update table_name set column_name=new
value[where condition]

DELETE
1.To Delete all records
delete from table_name;

2.To Delete specific records


delete from table_name where condition;
DQL Commands
SELECT
1.To select column wise data
select column1, column2…from table_name;
2.To select all data
select * from table_name;
DCL Commands
• GRANT
grant select insert update delete on table_name to
user_name;

• REVOKE
revoke select insert update delete on table_name
from user_name;

• SAVEPOINT & ROLLACK


To create savepoint
savepoint savepoint_name;
To get rollback
rollback to savepoint_name;

• COMMIT
commit;
SQL Operator

SET Operators
UNION
select column_name from table_1
union
select column_name from table_2;
select deptno from emp union select deptno from dept;
UNION ALL
select column_name from table_1
union all
select column_name from table_2;
INTERSECT
select column_name from table_1
intersect
select column_name from table_2;
MINUS
select column_name from table_1
minus
select column_name from table_2;

BETWEEN & LIKE


BETWEEN
select * from emp where sal between 25000 and
35000;

LIKE
select * from emp where name like "A%";
Unit 3) Interactive SQL And Advance
SQL, SQl performance Tuning (14m)

3.1 -Built Functions: String Arithmetic.


String Functions
1. LOWER (String)
2. UPPER(string)
3. INITCAP(String)
4. LPAD (char1,n,char2)
5. LTRIM( String,chars)
6. RTRIM(String,chars)
7. TRANSKATE(string, Form, to)
8. REPLACE (String, Search String,
Replace String)
9. LENGTH (String)
10. SUBSTR(String,m,n)
1. LOWER(String)-returns the string in lowercase.
2. UPPER(String)-returns the string in uppercase.
3. INITCAP(String)-to convert first letter of each word in capital
letter.

4. LPAD(char1,n,char2)- returns char1,left-padded to length n with


character specified in char2.

5. RPAD(char1,n,char2)- returns char1,right-padded to length n with


character specified in char2.

6. LTRIM(String,chars)-removes characters from the left(beginning)


of the string.

7. RTRIM(String,chars)- removes characters from the right(trailing)


of the string.

8. TRIM(String)- removes all spaces from string (beginning and


trailing)

9. TRANSLATE(String,from,to)-replace a sequence of characters in a


string with another set of characters. This is character to

character replacement.

10. REPLACE(String,search string,replace string)- This is word


to word replacement

11. LENGTH(String)- returns the length of string.

12. SUBSTR(String,m,n)-to display n no of character from mth


character from given string.
Arithmetic Functions

1.POWER(m,n)
2.ABS()
3.ROUND(M,N)
4.SQRT()
5.GREATEST (exp1,exp2,exp3)
6.LEAST(exp1,exp2,expn)

POWER(m,n)-To find the nth power of number m.

ABS()-It returns the absolute value.


ROUND (m,n)-It will rond up number m upto nth
digit.

SQRT()-To find out the square root of given number.

GREATEST(exp1,exp2,expn)- It returns greatest


value in a list of expression.

LEAST(exp1,exp2,expn)- It returns lowest value in a


list of expression.
Date and Time Functions

1. ADD_MONTHS(d,n)
2. LAST_DAY()
3. MONTHS BETWEEN (d1,d2)
4. NEXT_DAY (date,weekday)

1. ADD_MONTHS(d,n)- returns date after adding the


number of months specified in the function.
select add_months(sysdate,6) from dual;

2. LAST_DAY()-returns the last date of the number of


months specified in the function.
select sysdate,last_day(sysdate)from dual;

3. MONTHS_BETWEEN (d1,d2)- returns the number of


months between d1 and d2.
select MONTHS_BETWEEN(‘18-Oct-22’,’18-dec-22’)
from dual;

4. NEXT_DAY(date,weekday)- returns the date of the


first weekday coming after the date select
NEXT_DAY(’18-Oct-22’,’Monday’) from dual;

return coming Monday after 18-Oct-22


Aggregate Functions
MIN()-This function returns smallest value from
specified column of the table.
select min(sal) from emp;

MAX()-This function returns greatest value from


specified column of the table.
select max(sal) from emp;

SUM()-This function returns sum of all value


from specified column of the table.
select sum(sal) from emp;

AVG()-This function returns average of all value


from specified column of the table.
select avg(sal) from emp;

COUNT()-This function returns total no. of value


from specified column of the table.
select count(sal) from emp;
Queries Using group by , Having And Order
by clause

Group By Clause
select deptno,sum(sal) from emp group by deptno;

HAVING Clause
select deptno,sum(sal) from emp group by deptno
having deptno=10;

Order by Clause
select * from emp order by eno desc;

Joins -Inner and Outer Join sub Queries


INNER JOIN
Selecte
no,name,sal,emp.deptno,dept.dept_name,dept.loc from
emp inner join dept on emp.deptno=dept.deptno

LEFT OUTER JOIN


Select
eno,name,sal,emp.deptno,dept.dept_name,dept.loc
from emp left outer join dept on
emp.deptno=dept.deptno;
RIGHT OUTER JOIN
select
eno,name,sal,emp.deptno,dept.dept_name,dept.loc
from emp right outer join dept on
emp.deptno=dept.deptno;
SUB-QUERIES
Writing a query inside another query is known as nested
query or subquery.
Example-
select * from emp where deptno=(select deptno from emp
where name="Anil");
select * from emp where sal>(select sal from emp where
name="Dinesh");
CONCEPT OF VIEW
➢In SQL, a view is a virtual table containing the
records of one or more tables based on SQL
statement executed.
➢The changes made in a table get
automatically reflected in original table and
vice versa.
➢view is very useful in maintaining the
security of database.

Example-
mysql> create or replace view emp1 as select
empno,Ename,deptno from emp;

mysql> select * from emp1;

mysql> drop view emp1;


SEQUENCES
Sequences are database product features which help to
populate the primary key by incrementing and
retrieving its values.
Syntax-

CREATE SEQUENCE sequence-name


INCREMENT BY increment-value
START WITH initial-value
MAXVALUE maximum-value
MINVALUE minimum-value
CYCLE CACHE;

CREATE SEQUENCE sai


INCREMENT BY 2
START WITH 2
MAXVALUE 40
MINVALUE 2
CYCLE CACHE 5;

select * from sys.sequences where name=sai;


ALTERING SEQENCE
alter SEQUENCE sequence-name
INCREMENT BY increment-value
MINVALUE minimum-value

DROP SEQENCE
drop SEQENCE sequence-name
INDEXES
✓ Indexes are the special lookup tables which
are available to only databases search engine
for accessing data. Indexes speed up data
retrieval effectively.
✓ When we handling the very large databases
like SBI bank the retrieval of data from such
huge database becomes slower.
✓ An indexes used to speed up the SELECT
queries and also WHERE clause.
✓ Because of indexes input operations INSERT
& UPDATE gets slow down.

create index emp2 on emp(eno,name,sal);


show index from emp;

Types INDEXES
1. Simple Index
2. Composite Index
3. Unique Index
4. Implicit Index
5. Dropping Index
Simple Index - This is index created on a single
column of table.
create index emp2 on emp(eno);

Composite Index –Sometimes duplicate records


may be available in columns.in such case
composite indexing is better option to index on
data. This index created on a multiple column of
table
create index emp2 on emp(eno,name,sal);

Unique Index - Unique Index does not allow any


duplicate values to be inserted into the table.
create Unique index emp2 on emp(eno,name,sal);

Implicit Index- These indexes are automatically


created by the data server when an object is
created. Such indexes are created for primary key
and unique constrain.
To display the indexes
show index from table_name;
Dropping Index-
Drop index index_name
SYNONYM
A Synonym is alias or alternate name for a table,
view, sequence, or other schema object.
create synonym emp1 for emp;
drop synonym emp1;

Object Invisibility
Use of Synonym
Location Invisibility

• Object Invisibility
To keep the original object hidden from the
user.

• Location Invisibility
Created on tables & other objects that are not a
part of local database.
Unit 4 PL And SQL Programming(16m)

Introduction Of PL And SQL ,


➢PL/SQL stands for Procedure Language /
Structure Query Language. It is the
combination of SQL along with the procedural
features of programming languages.
➢PL/SQL includes procedural language
elements such as - conditions and loops. It
allows declaration of constants and variables,
procedures and functions, types and variables
of those types, and triggers. It can handle
exceptions (runtime errors).
➢ Arrays are supported involving the use of
PL/SQL collections. It has included features
associated with object- orientation. One can
create PL/SQL units such as procedures,
functions, packages, types, and triggers, which
are stored in the database for reuse by
applications.
Advantages Of PL/SQl
1. Block Structure
2. Tight Integration with SQl
3. Procedural language Capability
4. High Performance
5. Portability
6. High Productivity
7. Scalability
8. Manageability
9. Support For Object Oriented Programming
10. Support For Developing Web Applications
11. Support for Developing Server Pages
12. Error Handling
Pl/ SQl Block Diagram
Pl/ Sql Execution Environment

PL/SQL Data Types


Variable
Variables are placeholders that hold the values
which keep changing throughout the execution of a
PLSQL Block. Before using any variable, it needs to
be declared in the declaration section of the PL/SQL
block.
Syntax- variable_name datatype[:=value];
Example-emp_no number(6):=100;

Constant
A constant is a named memory location which holds a value
to be used in a PLSQL block that remains unchanged
throughout the execution of the program. Just like the
variable a constant also needs to be declared in the
declaration section.
Syntax- constant_name CONSTANT datatype:=value;
Example-pi CONSTANT number(3,2):=3.14;
Control Structure

- The Control Structures decide the execution flow of the


program depending on the conditions define by the
programmer.
- Following Control Structures can be used individually or
in combination to deal with a given problem.
- Selection Control Structure
- Iteration Control Structure
- Sequence Control Structure
-
Condition Control-
- IF Statement
- IF-THEN statement
- IF-THEN-ELSE statement
- NESTED IF-THEN-ELSE statement

If- Then Statement


- Syntax-
IF condition THEN
statement;
…………….
Statement;
END IF;
IF-THEN-ELSE statement
Syntax-
IF condition THEN
True_statement;
ELSE
False_Statement;
END IF;

NESTED-IF-THEN-ELSE statement
Syntax
IF <condition>
THEN
ELSIF<condition1>
THEN
ELSIF<condition2>
THEN
END IF;
➢CASE Statement-

Simple Case
Syntax-
CASE SECLETOR
WHEN expr1 THEN statement 1;
WHEN expr2 THEN statement 2;
:
:
ELSE statements n;
END CASE

Searched Case
Syntax-
CASE
WHEN searched condition THEN
statement 1;
WHEN searched condition THEN
statement 2;
:
ELSE statements n;
END CASE
Iterative Control
1 Loop Statement
Syntax-
LOOP
statements;
END LOOP;
EXIT Statements
Syntax-
EXIT[WHEN condition];

2 While Statement
Syntax-
WHILE condition LOOP
statements;
END LOOP;
For Statements
Syntax-
For counter In [REVERSE] lower_bound..
Upper_bound LOOP
Statements;
END LOOP:
CONTINUE Statement
Syntax-
CONTINUE;

CONTINUE-WHEN Condition
Syntax-
CONTINUE-WHEN (Condition)

Sequential Control
GOTO Statement
Syntax-
GOTO label;
:
:
<<label>>
Statements;
Exception Handling

- Exception is a warning or error condition which may


interrupt the program execution.
- It can be defined as an error situation, arising during
program execution.
- An exception is raised when an error occurs, the
normal execution is stopped and control transfers to
exception handler code.
- Exceptions are predefined or can be user defined. – E.g
ZERO_DIVIDE and STORAGE ERROR are predefined
exceptions.
- User defined Exceptions can be written in the declare
section of any PL/SQL block, subprogram, or package.
- Exception Handlers is a block of code written to handle
the raised exception. After an exception handler is
executed the control passes back to the next statement
after the statement where exception was raised.
- Handling the exceptions ensures that PLSQL blocks do
no exit unexpectedly.
Syntax
DECLARE
Declaration section….
BEGIN
Begin section…
EXCEPTION
WHEN Exception_one TEHN
Exception handler code to handle the errors
WHEN Exception_two TEHN
Exception handler code to handle the errors
WHEN others THEN
Exception handler code to handle the errors
END;
/
Producers
- A subprogram is a program unit/module that performs a
particular task. These subprograms are combined to
form larger programs. This is basically called the
'Modular design'. A subprogram can be invoked by
another subprogram or program which is called the
calling program.
- A subprogram can be
create
- At the Schema level
- Inside a package
- Inside a PL/SQL block
- At the schema level, subprogram is a standalone subprogram. It
is created with the CREATE PROCEDURE or the CREATE
FUNCTION statement. It is stored in the database and can be
deleted with the DROP PROCEDURE or DROP FUNCTION
statement

Syntax of producer

CREATE [OR REPLACE] PROCEDURE


procedure_name [(parameter_name [IN I OUT
/ IN OUT] type L, ...J)]

BEGIN
< phocedure_body >
END procedure_name;
Advantages Of Producer
1.
2.
3.
4.
5.
6.
7.
8.
9.

Creating Producer
Executing and Deleting a stored producer
Functions
- A standalone function is created using the CREATE
FUNCTION statement. The simplified syntax for the
CREATE OR REPLACE PROCEDURE statement
isas Follows:

Advantages Of Functions
10.
11.
12.
13.
14.
15.
16.
17.
18.
Creating Function

Executing and Deleting a stored Function


Database Trigger

Triggers are stored programs, which are automatically


executed or fired when some events occur.
Triggers are, in fact, written to be executed in
response to any of the following events —
A database manipulation (DML) statement
(DELETE, INSERT, or UPDATE) A
database definition (DDL) statement
(CREATE, ALTER, or DROP).
A database operation (SERVERERROR, LOGON,
LOGOFF, STARTUP, or SHUTDOWN).
s/ Triggers can be defined on the table, view, schema,
or database with which the event is associated.
Benefits of Triggers
Triggers can be written for the following purposes —
Generating some derived column values automatically
Enforcing referential integrity
Event logging and storing
information on table access
Auditing
Synchronous replication of tables
Imposing security authorizations
Preventing invalid transactions
Use Of Data Base Trigger

How To Apply Database trigger


Types Of Triggers

Syntax For Creating Trigger


CREATE [OR REPLACE 1 TRIGGER trigger_name
{BEFORE I AFTER I INSTEAD OF }
{INSERT [ORI I UPDATE IORI I DELETE)
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROWI
WHEN (condition)DECLARE
Declaration-statements
BEGIN
Executa ble-statements
EXCEPTION
Exception-handling-statements
END;
Syntax For Deleting triggers
Unit 5) Database Security and Transection
Processing

Database security concerns the use of a broad range


of information security controls to protect
databases against compromises of their
confidentiality, integrity and availability.
✓ The data
✓ The database applications or functions,
✓ The database systems,
✓ The database serves
✓ The associated network links
It involves various types or categories of controls, such as
technical, procedural/administrative and physical

Data Security Requirements


- Unauthorized access
- Misuse
- Hackers
- Malware infection
- Overloads,Performance
- Physical Damage
- Design flaws, Programming Bugs, Data loss
- Data corruption
- Network Security
- Access Control
Types of database user
- Application programmer
- Sophisticates user
- Specialized Users
- Stand Alone Users
- Native Users
Creating , Altering & Deleting User
- Creating user
create user username identified by password create
user dms identified by sairam;

- Altering user
alter user username identified by password alter user
dms identified by sairam123;

- Deleting user
drop user username[cascade] drop user dms cascade;
Database Privileges

Privileges define the access rights to database users on database


objects .
They also define rights to run a SQL statement, or PLSQL
package

System Privileges
It allows a user to perform administrative action in a
database.
✓ Create database
✓ Create procedure
✓ Create view
✓ Backup database
✓ Create table
✓ Create trigger
✓ Execute
Objective Privileges

Object privileges allow for the use of certain operations


database objects as authorized by another user.
Therefore the database objects can only be used by
1. The owner of the project
2. The owner of the schema in which the object is located
3. Users to whom the owner of the object has granted
privileges
4. Users to whom of the parent schema has granted
privileges

Grant & Revoke Privileges


Granting Privileges to User
grant select,insert,update,delete on tablename to username;
grant select,insert,update,delete on students to dcp;

Revoke privileges from User


revoke select,insert,update,delete on tablename from username;
revoke select,insert,update,delete on students from dcp;

Granting ALL Privileges to User


Grant all Privileges on *.* to username
Transection
A transaction is a series of operations performed as a
single logical unit of work on the Database
Management System. Transaction leads to
modification in the database contents.

Read (x) Input(x) Write(x); Output(x);

Properties Of transection
Transection States

Database Backup

- Database Backup is storage of data that means the copy of the


data.
- It is a safeguard against unexpected data loss and application
errors.
- It protects the database against data loss.
- If the original data is lost, then using the backup it can
reconstruct.

Types Of Database Backup


- Physical Backup
- Logical Backup
Types Of Failure
- System Crash
- Statement Failure
- Media failure
- Applications / w Error
-
Causes Of Failure
- File Corruption
- File System Damage
- Database H/W failure
Database Recovery
- Database Backup is storage of data that means the copy of the data.

- It is a safeguard against unexpected data loss and application errors.

- It protects the database against data loss.

- If the original data is lost, then using the backup it can reconstruct.

Recovery Techniques

Types of Complete Recovery


- Backward Recovery (Rollback)
- Forward Recovery (Roll Forward)
Important Questions
Chap 1-
.
1. Define: (i) Instance (ii) Schema Define iii) data abstraction, iv) data redundancy.
2. List any four advantages of DBMS
3. List disadvantages of typical file processing system
4. Define table and field.
5. Enlist DML commands
6. List DCL commands.
7. Explain overall structure of DBMS with the help of diagram
8. Draw three level architecture of DBMS.
9. State the difference between Relational and Hierarchical model
10. Distinguish between Network and Hierarchical model. (Any four points)
11. Explain strong and weak entity set.
12. Draw an E-R diagram of library management system considering issue and
return, fine
calculation facility, also show primary key, weak entity and strong entity.
or
Draw an ER diagram for library management system. (Use Books, Publisher
& Member entities).

Chap 2-
1. List the SQL operations and explain range searching operation ‘between’ and pattern
matching operator ‘like’ with example.
2. Explain difference between delete and truncate command with example.
3. Explain set operators with example.
4. Define the term: i) Candidate key ii) Primary key iii) foreign key.
5. Describe create & alter command with syntax & example.
6. Write a command to create table student (RNo., name, marks, dept.) with proper
datatype and RNo as primary key.
7. Consider the following database Employee(emp_id, emp_name, emp_city,
emp_addr,emp_dept, join_date)
a. Display the emp_id, of employee who live in city ‘Pune’ or ‘Nagpur’.
b. Change employee name, ‘Aayush’ to ‘Aayan’.
c. Display the total number of employee whose dept is 50
8. Consider the structure for book table as Book-Master (bookid, bookname, author,
no_of copies, price)Write down SQL queries for following
a. Write a command to create Book_master table.
b. Get authorwise list of all books.
c. Display all books whose price is between ` 500 & ` 800.
d. Display all books with details whose name start with ‘D’.
e. Display all books whose price is above ` 700.
f. Display all books whose number of copies are less than 10
9. Consider following schema :EMP (empno, deptno, ename, salary, designation,
join_date, DOB, dept_location). Write down SQL queries for following :
a. Display employees name & number in decreasing order of salary.
b. Display employee name & employee number whose designation is Manager.
c. Display age of employees with ename.
d. Display total salary of all employees.
e. Display employee names having deptno as 20 and dept_location is Mumbai.
f. Display name of employee who earned lowest salary.
10.Consider the table Student (name, marks, dept, age, place, phone, birthdate) Write SQL
query for
following :
a. To list students having place as ‘Pune’ or ‘Jalgaon’.
b. To list students having same department (dept) as that of ‘Rachana’.
c. To change marks of ‘Rahul’ from 81 to 96.
d. To list student name and marks from ‘Computer’ dept.
e. To list student name who have marks less than 40.
f. To list students who are not from ‘Mumbai’

11.Consider the following table employee (Emp_id, Emp_name,Emp_age)


i) Display details of employees whose age is less than 30.
ii) Display details of employees whose age is in between the range 30 to 60.
iii) Display total number of employee whose age is 60.
iv) Display names of employees whose name starts with 'S'.
v) Display details of employees whose name end with 'd'.
vi) Display details of employees whose age is greater than 50 and whose name contain 'e'.
12.
i) Create table Student (S_id, S_name, S_addr, S_marks) with proper data type and size.
ii) Insert row (5, ‘ABC’, ‘RRRRR’, 79) into student table.
iii) Update marks of student 85 where S_id is 5.

13. Explain any two DDL commands along with example


14.Define Normalization. Explain 2NF with example.
15.List any four data types in SQL

Unit 03
1. State the use of Avg function with example.
2. List any four string functions in SQL.
3. Write syntax for creating synonyms with example.
4. Enlist four aggregate functions.

1.Explain any four string functions with example.


2.Describe the concept of view with example. State its purpose. or
Describe Views and write a command to create view or
Write and explain syntax for creating view with example.

3.Define index. Explain it’s types. or


Create simple and composite index. Write command to drop above index. or
Write syntax for
i) Create Index ii) Drop Index

4.Explain any four aggregate functions with example.

5.Consider the schema Customer (Cust-id, Cust_name, Cust_addr,Cust_city)


Create a view on Customer (Cust_id, Cust_name) where Cust_city is ‘Pune’
Create a sequence on Cust_id

1. Create a sequence
i) Sequence name is Seq_1, Start with 1, increment by 1, minimum value 1, maximum value
20.
ii) Use a seq_1 to insert the values into table Student (ID Number (10), Name char (20));
iii) Change the seq_1 max value 20 to 50.
iv) Drop the sequence.

Unit 4
1. State any two advantages of functions in PL/SQL.
2. Define cursor. List the two types of cursor
3. State any four PL/SQL datatypes.
4. List two advantages of PL/SQL.
1. Explain implicit and explicit cursors.
2. Describe exception handling in brief.
3. Explain Exception handling with it’s types.
4. Explain exception handling in PL/SQL with example.
5. Explain conditional control in PL/SQL with example.
6. Define database trigger. How to create and delete trigger ?
7. Write and explain syntax for creating Trigger.
8. State the use of database trigger and also list types of trigger.
9. Explain function in PL/SQL with example
10.Explain any one control structure in PL/SQL with example.
11.Explain PL/SQL block structure with the help of diagram.
12.Draw the block structure of PL/SQL . List advantages of PL/SQL.
13.Write step by step syntax to create, open and close cursor in PL/SQL.
14.Explain cursor with example.
15.Write a PL/SQL program which accept the customer ID from the user if user enters
an invalid ID then the exception invalid_id is raised using exception handling.
16.Write a PL/SQL program to calculate factorial of a given number.
6 Marks Questions
1. Write a PL/SQL program to print n even numbers using For Loop.
2. Write a PL/SQL program, which accept the number from user. If user enters an odd
number then exception invalid number is raised using user defined exception
handling
Unit 05
1. Explain ACID properties of traction.
2. Explain transaction ACID properties
3. Describe database backups with it’s types.
4. Create user ‘RAM’.ii) Grant create, select, insert, update, delete privileges to user
‘RAM’.iii) Remove update privilege from user ‘RAM’.

5. With neat sketch describe Transaction states diagram.


6. Explain state of transaction with the help of diagram.
7. State the concept of database recovery.
8. State types of database user.
9. Explain recovery techniques with example
10.Explain the four roles of database administrator.
11.Describe commit and rollback with syntax and example.
12.Explain database security with it’s requirements in detail.
1. Describe database privileges. Write down the procedure for granting & revoking
privileges in database objects to the users.
2. Write SQL command for following :
a) Create user
b) Grant privileges to user
c) Remove privileges from user
3. i) Create user ‘Rahul’
ii) Grant create, select, insert, update, delete, drop privilege to ‘Rahul’.
iii) Removes the select privilege from user ‘Rahul’.

You might also like