DBMS Lesson
DBMS Lesson
MANAGEMENT
SYSTEM
(22319)
Unit 1..Database System Concept
1. Concept of Data,Database,DBMS
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
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 )
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
Types of Schema
1. Physical Schema
2. Logical Schema
3. View Schema
DATA IMPEDANCE
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.
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.
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
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
Management
Faculty
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.
4.Normalization
Types of Normalization.
1. First normal form (1NF)
2. Second normal form,(2NF)
3. Third normal form.(3NF)
First Normal Form.
Course Content
Programming Java, c++
Web HTML,PHP,ASP
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
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);
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;
• REVOKE
revoke select insert update delete on table_name
from user_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;
LIKE
select * from emp where name like "A%";
Unit 3) Interactive SQL And Advance
SQL, SQl performance Tuning (14m)
character replacement.
1.POWER(m,n)
2.ABS()
3.ROUND(M,N)
4.SQRT()
5.GREATEST (exp1,exp2,exp3)
6.LEAST(exp1,exp2,expn)
1. ADD_MONTHS(d,n)
2. LAST_DAY()
3. MONTHS BETWEEN (d1,d2)
4. NEXT_DAY (date,weekday)
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;
Example-
mysql> create or replace view emp1 as select
empno,Ename,deptno from emp;
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.
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);
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)
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
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
Syntax of producer
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
- 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
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
Properties Of transection
Transection States
Database Backup
- If the original data is lost, then using the backup it can reconstruct.
Recovery Techniques
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’
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. 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’.