Dbms For Final
Dbms For Final
Dbms For Final
2)types of files are data files , text files , program files , directory files
Retrival operation = When we want to extract the data from file for reading purpose then we perform
retrieval operation on the file. Retrieval operations do not change the contents (data) of file; it only
locates the records in file.
Upddate operation = Update operation on the other hand; change the file by modifying the records,
deleting the records and inserting new records. That is we actually modify the contents in file in
update operation
1.find = The goal of this operation is to locate the record or records that satisfy the search criteria. A
block that contains the records is transferred to the main memory and the records are searched. The
first record that matches the search criteria is located and the search continues for other records
until the end of file is reached.
2. Read = The goal of this operation is to read the contents of the record
3. Read Next: Searches the next record that matches the selection condition and when found, the
contents of record are copied to the program variable or work area.
4. modify = This command modifies the field values/data of the current record then writes modified
record back to disk
5. Insert = This command is used to insert a new record into thre file
6. Delete = This command is used to delete the current record and update the disk file after the deletion
3. Constraints ==> we can say that the Constraints within a database are rules, which control values
allowed in columns and also enforce the integrity between columns and tables.
4. schema ==> Schema describes the organization of data in the data base. schema is the logical
structure of the database
Entity ==> Entity is anything about which information is stored. suppose we are going to
maintain school level database. In this database student, teachers, books, subjects can be defined as
different entities of that school. Or in a Bank database we can define customer, account etc as different
entities of that particular bank.
Doamin ==> In short a domain is a set of values the attribute can have.
Record ==> The data representation in storage of each instance of an entity commonly
called as record. And it is also called as tuple.
Instance ==> An instance of the entity represented by a set of specific values for each of the attributes
at particular time period
Unit 2
Q1) What is database management system?
= A Database Management system (DBMS) is a collection of programs (or we can say it as a
software) that enables you to store, modify and extract information from a database.DBMS
is software designed to assist in maintaining and utilizing large collections of data in
database
1.Transaction management :
A transaction is sequence of database operations that represents a logical unit of work
(delete record, update record, modify a set of records etc).
DBMS manages these transactions. When the DBMS does a “commit” the changes made
by the transaction are made permanent. If you don’t want to
make changes permanent you can rollback the transaction and the database remain in its
original state
2. Concurrency control :
In a database, number of processes or actions (such as delete record, update record,
insert new record etc) may execute simultaneously i.e. concurrently. So this simultaneous
or concurrent execution of actions must be managed somehow.
DBMS provides concurrency control mechanism by coordinating the actions of database
manipulation processes.
3. Recovery management :
A simple meaning of recovery is to return to a normal/stable condition.
Recovery mechanism in DBMS ensures that the database returned to a consistent state
after a transaction fails or abort i.e. database should not be in inconsistent state.
4. Security management :
Security mechanism of DBMS ensures that only authorized users are given
access to the data in database.
5. Language interface :
To handle data in database a user has to use some kind of language, which will be
understandable for database.
And that’s why DBMS provides languages support, which is used to define and
manipulate the data in database
Basically there are two languages used by DBMS to interact between user and database
and those are DDL and DML.
The data structures are created by the data definition language (DDL) commands.
The data manipulation is done using the data manipulation language (DML) commands.
4. Credit card transactions: For purchases on credit cards and generation of monthly
statements.
6. Finance: For storing information about holdings, sales and purchase of financial
instruments such as stocks and bonds.
8. Manufacturing: For management of supply chain and for tracking production of items in
factories, inventories of items in warehouses/stores and orders for items.
9. Human Resources: For information about employees, salaries, payroll taxes and benefits
and for generation of paychecks.
10.Web based services: For taking web users feedback, responses, resource sharing online
shopping etc.
Q4) What are the different types of database users?
= 1) Application Programmers:
Application programmer is the person who is responsible for
implementing the required functionality of database for the end user. Application
programmer works according to the specification provided by the system analyst.
2) End Users:
End users are those persons who interact with the application directly. They are
responsible to insert, delete and update data in the database. They get information from the
system as and when require
3) Naive users: Naive users are those users who do not have any technical knowledge
about the DBMS. They use the database through application programs by using simple
user interface. They perform all operations by using simple commands (menus and
buttons) provided in the user interface.
4) Sophisticated users : Sophisticated users are the users who are familiar with the
structure of database and facilities of DBMS. Such users can use a query language such
as SQL to perform the required operations on databases. Some
sophisticated users can also write application programs.
1. physical level = This is the lowest level of abstraction which describes how data are
actually stored
It also describes complex low-level data structures in detail
The physical schema (physical level) specifies additional storage details for
data in database. Essentially, the physical schema summarizes how the relations described
in the conceptual schema are actually stored on secondary storage devices such as disks
and tapes.
2. logical level = Describes what data are stored in the database & what relationships exist
among those data
Describes the entire database in terms of relatively simpler structures
The conceptual schema (sometimes called the logical schema) describes the stored
data in terms of the data model of the DBMS.
3. View level = Highest level of abstraction which describes only a part of the DB
User’s view of the DB. This level describes that part of the DB that is relevant to
each user.
Q6) what is DDL and DML?
= 1) The Data Definition Language (DDL) is used to create and destroy databases and
database objects. Database administrators will primarily use these commands during the
setup and removal phases, of a database project.
Some examples:
a. Procedural DML -
A low-level or procedural DML allows the user, i.e. programmer to specify what data is
needed and how to obtain it. This type of DML typically retrieves individual records
from the database and processes each separately. The programmers use the low-level
DML.
Example of procedural DML is “Relational Algebra”.
A high-level or non-procedural DML allows the user to specify what data is required
without specifying how it is to be obtained. Many DBMSs allow high-level DML statements
either to be entered interactively from a terminal or to be embedded in a general-purpose
programming language.
Structure of DBMS ( from youtube )
Q)What is metadata ?
=>Metadata is loosely defined as data about data.
For example: a web page may include metadata specifying what language it's written
in, what tools were used to create it, and where to go for more on the subject,
allowing browsers to automatically improve the experience of users.
Metadata is defined as data providing information about one or more aspect of the data :
Q)What is the structure of the DBMS? => . The components of DBMS perform these
requested operations on the database and provide necessary data to the users. The
various components of DBMS are shown below :
2. DML compiler : The DML commands such as insert, update, delete, retrieve
from the application program are sent to the DML compiler for compilation into
object code for database access. The object code is then optimized in the best way
to execute a query by the query optimizer and then send to the data manager.
3. Data Manager : The Data Manager is the central software component of the
DBMS also knows as Database Control System.
Data - names of the tables, names of attributes of each table, length of attributes, and
number of rows in each table.
• Relationships between database transactions and data items referenced by them, which
is useful in determining which transactions are affected when certain data definitions are
changed.
6. Compiled DML - The DML complier converts the high level Queries into low level file
access commands known as compiled DML.
7. End Users - End users are the one who perform various operations on the database
Unit 4
What is an ER model?
==> When anyone wants to design any database it is necessary to represent all data
such that user can easily visualize database and relationship that exists between the
tables, this can be done with help of
ER (Entity –Relationship) model ER model is a graphical picture of the data for a particular database.
To
represent real world object that is distinguishable from other object we use entities & for
describing properties of entities we use attribute
3.Entity Set --> In ER model a specific table row is referred as an entity instance or entity occurrence.
Each entity set has a key. All entities in an entity set have the same set of attributes. Thus entity set is a
set of entities of the same type that share the same properties or attributes. Set of entities of particular
type is known as Entity Set.
4.Domain --> Each attribute is connected with a set of values that is known as
domain. The domain defines the possible value that an attribute may grasp.
5.Entity Types --> The existence of an entity may depend on the existence of one or
more other entities, such an entity is said to be existence dependent.
Strong Entities --> An entity set that has a primary key is known as strong entity set. A strong entity
is independent of other entities and can exist on its own.
Recursive Entities --> A recursive entity is one in which a relation can exist between occurrences of
the same entity set. This occurs in a unary relationship
Composite Entities --> Composite means thing composed of other things. Similar to that composite
entity is composed of many parts. It is used to link the relationships that exist between many
relationships
3)Secondary key ==> Means we can use this key to identify records that might not be unique
4)Compound key ==> Compound key is known as composite key or concatenated key. It consists of
2 or more attributes. If in a table, no single data element is identified uniquely, then we
can form compound key by combining multiple elements to identify the data element.
1.One-to-One Relationship :- One manager in the department manages only one department
a. Unary Relationship: -
An Entity can be related to itself, such kind of relationship is known as Unary or
Recursive Relationship. A unary relationship exists when an association is
maintained within a single entity.
b.Binary relationship:-A binary relationship exists when two entities are associated.
c.Ternary relationship:-A ternary relationship exists when three entities are associated
Unit 5
Q)What is normalization?
==> SQL offers to use different types of queries but sometime it may happen that we
get redundant, inconsistent data, which is not sufficient. To avoid problems
regarding to database, it necessary to convert database into normalize form means
normal, that concern to standard or norm. So we need normalization of database.
If we want to create good relational database design we must remember things like
avoiding redundant data, ensuring the relationships among attributes and managing
the consistency of the database.
a) Full Functional Dependency --> If we have Functional Dependency P->Q then it can be Full Functional
Dependency only when we cannot remove any attribute of Q from P.In other words Q is fully
functionally dependent on P and there should not be any R->Q, where R is a proper subset of P.
In this case (RollNo, Subject_Code) both form composite key (primary key with more
than one attribute) means if we want to find marks for particular subject we need
RollNo and Subject_ Code.
I.e. Functional Dependency exists in this relation as follows:- Marks->RollNo,
Subject_Code
c)Transitive Dependency:- A Functional dependency between two (or more) non-key attributes in
relation is known as Transitive functional dependency.
Un-Normalized Form :
It is a relation that contains non-atomic values. A non-atomic value means it can
be decomposed .To create UN normalize form we must list attribute of entity,
identify repeating groups of attributes, their keys, identify main keys.
Note --> We can say that a relation R is said to be in 2NF if relation is in 1NF and every
attribute is depend on Primary key.
If primary key of relation is single attribute means that it has only one value,
and then we did not require to convert it in 2NF.
But if primary key exists in relation is not single means primary key is
composite attributes then we require to identify primary key and functional
dependencies that exist in relation for 1NF. o If any partial dependency is
depending upon primary key, then remove those dependencies by placing
them in new relation along with copy of determinant
Q)What is denormalization?
==> De-normalization is the process of converting normalized form into unnormalized
form. It is a technique to move from higher to lower normal forms of database.
Disadvantages of Denormalization:- It
makes updating process slow.
It increase the size of tables.
It makes coding more complex.
It is mostly application specific .So if application changes, it need to revaluate
Unit 6
Q)What are SQL statements?
=> It provides an interface to relational database. All SQL
statements are like instructions to the database. Query is used to
give instruction to database.There are 3 types of SQL statements
1) SELECT ===>
The SELECT statement is used to select data from a
database.
The data returned is stored in a result table, called the
result-set.
3) ORDER BY ===>
ORDER BY clause is used to sort the result in the
ascending and descending order
Syntax ==>
way 1 =
INSERT INTO table_name (column1, column2,
column3, ...)
VALUES (value1, value2, value3, ...);
way 2 =
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
6)UPDATE ===>
The UPDATE statement is used to modify the existing
record in the table
Syntax --
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Note ==> IT is important to use where clause without
where clause the whole table would be updated
7)DELETE ===>
DELETE statement is used to delete the existing record in
the table
Syntax -->
DELETE FROM table_name WHERE condition;
8)LIMIT ==>
The LIMIT clause is used to specify the number of records to
return.
The LIMIT clause is useful on large tables with thousands of
records. Returning a large number of records can impact
performance
Syntax ==>
SELECT COUNT(column_name)
WHERE condition;
AVG --->
The AVG() function returns the average value
of a numeric column
SELECT AVG(column_name)
FROM table_name
WHERE condition;
SUM --->
The SUM() function returns the total sum of a
numeric column.
SELECT SUM(column_name)
FROM table_name
WHERE condition;
Synatx :
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
Syntax :
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
1)Rename: -
We can rename any table by using RENAME SQL command. If we
use
rename command, the data will not be lost only the table name will
be changed to
new name
2)Tuple Variables: -
Set of one or more attributes is known as tuples. Tuple variables
are used in the SQL clause known as FROM.
3. Set Operations: -
SQL set operators allows to join (combine) results from two or
more SELECT statements. It combines rows from different
queries. The four set operators union,
union all, intersect and minus allows to serially combine more than
one select statement.
Q)UNION operation?
=>UNION combines the results of two SQL queries into a single
table of all
matching rows. The two queries must result in the same number of
columns and compatible data types in order to unite.
Syntax: -
SELECT * FROM Table1 UNION
SELECT * FROM Table2
Q)Intersect Operator?
=> The Intersect operator takes the results of two queries and
returns only rows that appear in both result sets. This operator
does not distinguish between Nulls. It
removes duplicate rows from the final result set. The INTERSECT
ALL operator does not remove duplicate rows from the final
result set.
Q)Minus operator?
=>EXCEPT operator also called MINUS .It returns
rows that appear in one input
but not in the other, so it also eliminates
duplicates. The EXCEPT ALL operator does not
remove duplicates. The EXCEPT operator can’t
distinguish between Nulls in case if you are
doing row removal and duplicate data removal
from table
unit 7
Q)Transaction concept
=> The execution of a program that includes
database access operations is called the
transaction. A transaction is a unit of program
execution that accesses and updates various
data items. Whenever we read from and/or write
(update) a database, we create a transaction. If
the database operations in a transaction do not
modify the data in the database, but only reads
the data, then the transaction is called as the
read-only transaction.A transaction is a single
unit of database operations that are either
completed entirely or not performed at all. The
transaction should be completed or aborted, no
intermediate states are allowed.The transaction
consists of simple SQL
statements such as select, insert, delete, When
the transaction is executing, the DBMS must
ensure that the data item used should not be
accessed by any other transaction.
Q)What are the properties of the transactions?
=> Transactions properties have the acronym of
ACID properties which stands for Atomic ,
consistent , isolation , Durability.
1) Atomicity: A transaction is an atomic unit of
processing; it is either performed in its entirety
or not performed at all.
2) Consistency Preservation: A correct
execution of a transaction must take the
database from one consistent state to another.
3) Isolation: A transaction should not make its
updates visible to other transactions until it is
committed. This property is useful in multi-user
database environment because several different
users can access and update the database at the
same time.
4) Durability or Permanency: Once a
transaction changes the database and the
changes are committed, these changes must
never be lost because of the software or
hardware failures.
3)Cascadeless schedules:
=> r each pair of transactions Ti and Tj such that
Tj reads a data item previously written by Ti,
then the commit operation of Ti should appear
before the read operation of Tj. This schedule
is called as Cascadeless Schedule. In this type
of schedule cascading rollbacks cannot occur.
Unit 8
Q)What is PL Sql?
=> PL stands for procedural extension to SQL. PLSQL has the features of programming language and
can executes programs just as any other programming language. SQL commands are included in the
proceudral blocks. Inorder to begin a PLSQL program we need to use the "Begin" keyword and to end
the program we use the "end" keyword and in between that we write in those block.Features of the
PLSQL are as follows:
1)Performance benefits
2)Modularization
3)Portable
4)Programming features
5)Exception handling
Q)PL/SQL architecture?
=>The architecture of the PL?SQL is divided into three different sectors. 1)PL/SQL
block
2)PL/SQL engine
3)SQL statement executor
When an application program or a user invokes a PL/SQL block, it is submitted to the PL/SQL engine
available locally. PL/SQL engine extracts the Procedural Language statements of the block. These
statements are then executed separately by the PL/SQL processor. The SQL statements in the block are
passed to the SQL processor of Oracle server. These are separately executed
1)PLS_INTEGER =
Signed integer in range -2,147,483,648 through 2,147,483,647, represented in 32 bits
2)BINARY_INTEGER =
Signed integer in range -2,147,483,648 through 2,147,483,647, represented in 32 bits
Q)Procedures in PL/SQL
=>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. The PL/SQL contains these two:
The procedure contains a header and a body.
Header: The header contains the name of the procedure and the parameters or variables passed to the
procedure.
Body: The body contains a declaration section, execution section and exception section similar to a
general PL/SQL block.
hen you want to create a procedure or function, you have to define parameters .There is three ways to
pass parameters in procedure:
IN parameters: The IN parameter can be referenced by the procedure or function. The value of the
parameter cannot be overwritten by the procedure or the function.
OUT parameters: The OUT parameter cannot be referenced by the procedure or function, but the value
of the parameter can be overwritten by the procedure or function.
INOUT parameters: The INOUT parameter can be referenced by the procedure or function and the value
of the parameter can be overwritten by the procedure or function.
PL/SQL facilitates programmers to catch such conditions using exception block in the program and an
appropriate action is taken against the error condition.
1) System-defined Exceptions
2) User-defined Exceptions : PL/SQL facilitates their users to define their own exceptions according to
the need of the program. A user-defined exception can be raised explicitly, using either a RAISE
statement or the procedure DBMS_STANDARD.RAISE_APPLICATION_ERROR.
Triggers are stored programs, which are automatically executed or fired when some event occurs.