Question-Answer
Question-Answer
MANGEMENT
SYSTEM
Digital Notes By
A DBMS is a collection of interrelated data and a set of program to access those data.
1) Data Redundancy
Data Redundancy means same information is duplicated in several files. This makes data
redundancy.
2) Data Inconsistency
Data Inconsistency means different copies of the same data are not matching. That means
different versions of same basic data are existing. This occurs as the result of update
operations that are not updating the same data stored at different places. Example: Address
Information of a customer is recorded differently in different files.
It is not easy to retrieve information using a conventional file processing system. Convenient
and efficient information retrieval is almost impossible using conventional file processing
system.
4) Data Isolation
Data are scattered in various files, and the files may be in different format, writing new
application program to retrieve data is difficult.
5) Integrity Problems
The data values may need to satisfy some integrity constraints. For example the balance field
Value must be greater than 5000. We have to handle this through program code in file
processing systems. But in database we can declare the integrity constraints along with
definition itself.
6) Atomicity problems:
A computer system, like any other mechanical or electrical device, is subject to failure. In
many applications, it is crucial that, if a failure occurs, the data be restored to the consistent
state that existed prior to the failure.
Example:
Consider a program to transfer $50 from account A to account B. If a system failure
occurs during the execution of the program, it is possible that the $50 was removed
from account Abut was not credited to account B, resulting in an inconsistent database
state.
7) Concurrent-access anomalies.
For the sake of overall performance of the system and faster response, many systems allow
multiple users to update the data simultaneously. In such an environment, interaction of
concurrent updates may result in inconsistent data.
Example:
Consider bank account A, containing $500. If two customers withdraw funds (say $50
and $100 respectively) from account A at about the same time, the result of the
concurrent executions may leave the account in an incorrect (or inconsistent) state.
Suppose that the programs executing on behalf of each withdrawal read the old
balance, reduce that value by the amount being withdrawn, and write the result back.
If the two programs run concurrently, they may both read the value $500, and write
back $450 and $400, respectively.
Depending on which one writes the value last, the account may contain either $450 or
$400, rather than the correct value of $350. To guard against this possibility, the
system must maintain some form of supervision.
But supervision is difficult to provide because data may be accessed by many
different application programs that have not been coordinated previously.
8) Security problems.
Not every user of the database system should be able to access all the data.
For example, in a banking system, payroll personnel need to see only that part of the
database that has information about the various bank employees. They do not need
access to information about customer accounts. But, since application programs are
added to the system in an ad hoc manner, enforcing such security constraints is
difficult. These difficulties, among others, prompted the development of database
systems. In what follows, we shall see the concepts and algorithms that enable
database systems to solve the problems with file-processing systems.
9) Data isolation
Because data are scattered in various files, and files may be in different formats, writing new
application programs to retrieve the appropriate data is difficult.
Reduction of Redundancy:
This is perhaps the most significant advantage of using DBMS. Redundancy is the
problem of storing the same data item in more one place. Redundancy creates several
problems like requiring extra storage space, entering same data more than once during
data insertion, and deleting data from more than one place during deletion. Anomalies
may occur in the database if insertion, deletion etc are not done properly.
Sharing of Data:
In a paper-based record keeping, data cannot be shared among many users. But in
computerized DBMS, many users can share the same database if they are connected
via a network. Data Integrity: We can maintain data integrity by specifying integrity
constrains, which are rules and restrictions about what kind of data may be entered or
manipulated within the database. This increases the reliability of the database as it can
be guaranteed that no wrong data can exist within the database at any point of time.
Data independence:
Application programs should be as independent as possible from details of data
representation and storage. The DBMS can provide an abstract view of the data to
insulate application code from such details.
Efficient data access:
A DBMS utilizes a variety of sophisticated techniques to store and retrieve data
efficiently. This feature is especially important if the data is stored on external storage
devices. Data integrity and security: If data is always accessed through the DBMS, the
DBMS can enforce integrity constraints on the data. For example, before inserting
salary information for an employee, the DBMS can check that the department budget
is not exceeded. Also, the DBMS can enforce access controls that govern what data is
visible to different classes of users.
Data administration:
When several users share the data, centralizing the administration of data can offer
significant improvements. Experienced professionals who understand the nature of the
data being managed, and how different groups of users use it, can be responsible for
organizing the data representation to minimize redundancy and fine-tuning the storage
of the data to make retrieval efficient.
Concurrent access and crash recovery:
A DBMS schedules concurrent accesses to the data in such a manner that users can
think of the data as being accessed by only one user at a time. Further, the DBMS
protects users from the effects of system failures.
Reduced application development time:
Clearly, the DBMS supports many important functions that are common to many
applications accessing data stored in the DBMS. This, in conjunction with the high-
level interface to the data, facilitates quick development of 44 applications. Such
applications are also likely to be more robust than applications developed from
scratch because many important tasks are handled by the DBMS instead of being
implemented by the application.
Danger of a Overkill:
For small and simple applications for single users a database system is often not
advisable.
Complexity: A database system creates additional complexity and requirements. The
supply and operation of a database management system with several users and
databases is quite costly and demanding.
Qualified Personnel: The professional operation of a database system requires
appropriately trained staff. Without a qualified database administrator nothing will
work for long.
Costs: Through the use of a database system new costs are generated for the system
itself but also for additional hardware and the more complex handling of the system.
Lower Efficiency: A database system is a multi-use software which is often less
efficient than specialized software which is produced and optimized exactly for one
problem.
A database system provides a data definition language to specify the database schema
and a data manipulation language to express database queries and updates.
DATA-DEFINITION LANGUAGE
Example:
Create table account (account-number char(10), balance integer)
Example
Commit
Savepoint
We can define a data dictionary as a DBMS component that stores the definition of data
characteristics and relationships. It is simple ―data about data‖ as metadata. The DBMS data
dictionary provides the DBMS with its self describing characteristic. In effect, the data
dictionary resembles and X-ray of the company‘s entire data set, and is a crucial element in
the data administration function.
The two main types of data dictionary exist, integrated and stand alone.
1) An integrated data dictionary is included with the DBMS. For example, all relational
DBMSs include a built in data dictionary or system catalog that is frequently accessed
and updated by the RDBMS.
2) Other DBMSs especially older types, do not have a built in data dictionary instead the
DBA may use third party stand alone data dictionary systems
Data dictionaries can also be classified as active or passive. An active data dictionary is
automatically updated by the DBMS with every database access, thereby keeping its access
information up-to-date. A passive data dictionary is not updated automatically and usually
requires a batch process to be run. Data dictionary access information is normally used by the
DBMS for query optimization purpose.
The data dictionary‘s main function is to store the description of all objects that interact with
the database. Integrated data dictionaries tend to limit their metadata to the data managed by
the DBMS. Stand alone data dictionary systems are more usually more flexible and allow the
DBA to describe and manage all the organization‘s data, whether or not they are
computerized. Whatever the data dictionary‘s format, its existence provides database
designers and end users with a much improved 47 ability to communicate. In addition, the
data dictionary is the tool that helps the DBA to resolve data conflicts. Although, there is no
standard format for the information stored in the data dictionary several features are common.
For example, the data dictionary typically stores descriptions of all:
Data elements that are define in all tables of all databases. Specifically the data dictionary
stores the name, data types, display formats, internal storage formats, and validation rules.
The data dictionary tells where an element is used, by whom it is used and so on.
Tables define in all databases. For example, the data dictionary is likely to store the name
of the table creator, the date of creation access authorizations, the number of columns,
and so on.
Indexes define for each database tables. For each index the DBMS stores at least the
index name the attributes used, the location, specific index characteristics and the creation
date.
If the data dictionary can be organized to include data external to the DBMS itself, it
becomes an especially flexible to for more general corporate resource management. The
management of such an extensive data dictionary, thus, makes it possible to manage the use
and allocation of all of the organization information regardless whether it has its roots in the
database data.
There are four different types of database-system users, differentiated by the way they expect
to interact with the system. Different types of user interfaces have been designed for the
different types of users.
1) Naive users are unsophisticated users who interact with the system by invoking one of
the application programs that have been written previously. For example, a bank teller
who needs to transfer $50 from account A to account B invokes a program called transfer.
This program asks the teller for the amount of money to be transferred, the account from
which the money is to be transferred, and the account to which the money is to be
transferred.
As another example, consider a user who wishes to find her account balance over the
World Wide Web. Such a user may access a form, where she enters her account number.
An application program at the Web server then retrieves the account balance, using the
given account number, and passes this information back to the user. The typical user
interface for naive users is a forms interface, 48 where the user can fill in appropriate
fields of the form. Naive users may also simply read reports generated from the database.
2) Application programmers are computer professionals who write application programs.
Application programmers can choose from many tools to develop user interfaces. Rapid
application development (RAD) tools are tools that enable an application programmer to
construct forms and reports without writing a program. There are also special types of
programming languages that combine imperative control structures (for example, for
loops, while loops and if-then-else statements) with statements of the data manipulation
language. These languages, sometimes called fourth-generation languages, often include
special features to facilitate the generation of forms and the display of data on the screen.
Most major commercial database systems include a fourth generation language.
A person who has such central control over the system is called a database administrator
(DBA).
The functions of a DBA include:
Schema definition. The DBA creates the original database schema by executing a set of data
definition statements in the DDL.
Schema and physical-organization modification. The DBA carries out changes to the
schema and physical organization to reflect the changing needs of the organization, or to alter
the physical organization to improve performance.
Granting of authorization for data access. By granting different types of authorization, the
database administrator can regulate which parts of the database various users can access. The
49 authorization information is kept in a special system structure that the database system
consults whenever someone attempts to access the data in the system.
Routine maintenance. Examples of the database administrator‘s routine maintenance
activities are:
1. Periodically backing up the database, either onto tapes or onto remote servers, to prevent
loss of data in case of disasters such as flooding.
2. Ensuring that enough free disk space is available for normal operations, and upgrading disk
space as required.
3. Monitoring jobs running on the database and ensuring that performance is not degraded by
very expensive tasks submitted by some users.
Data independence, which can be defined as the capacity to change the schema at one level
of a database system without having to change the schema at the next higher level. We can
define two types of data independence:
1. Logical data independence is the capacity to change the conceptual schema without
having to change external schemas or application programs. We may change the conceptual
schema to expand the database (by adding a record type or data item), or to reduce the
database (by removing a record type or data item). In the latter case, external schemas that
refer only to the remaining data should not be affected. Only the view definition and the
mappings need be changed in a DBMS that supports logical data independence. Application
programs that reference the external schema constructs must work as before, after the
conceptual schema undergoes a logical reorganization. Changes to constraints can be applied
also to the conceptual schema without affecting the external schemas or application
programs.
2. Physical data independence is the capacity to change the internal schema without having
to change the conceptual (or external) schemas. Changes to the internal schema may be
needed because some physical files had to be reorganized—for example, by creating
additional access structures—to improve the performance of retrieval or update. If the same
data as before remains in the database, we should not have to change the conceptual schema.
Whenever we have a multiple-level DBMS, its catalog must be expanded to include
information on how to map requests and data among the various levels. The DBMS uses
additional software to accomplish these mappings by referring to the mapping information in
the catalog. Data independence is accomplished because, when the schema is changed at
some level, the schema at the next higher level remains unchanged; only the mapping
between the two levels is changed. Hence, application programs referring to the higher-level
schema need not be changed.
Hierarchical databases.
Network databases.
1) Hierarchical Database Model we have to learn about the databases. It is very fast
and simple. In a hierarchical database, records contain information about there groups
of parent/child relationships, just like as a tree structure. The structure implies that a
record can have also repeating information.
In this structure Data follows a series of records; It is a set of field values attached to
it. It collects all records together as a record type. These record types are the
equivalent of tables in the relational model, and with the individual records being the
equivalent of rows. To create links between these record types, the hierarchical model
uses these type Relationships.
2) Network Database: A network databases are mainly used on large digital computers.
It more connections can be made between different types of data, network databases
are considered more efficiency It contains limitations must be considered when we
have to use this kind of database.
It is Similar to the hierarchical databases, network databases .Network databases are
similar to hierarchical databases by also having a hierarchical structure. A network
database looks more like a cobweb or interconnected network of records. In network
databases, children are called members and parents are called occupier. The
difference between each child or member can have more than one parent.
3) Relational Databases:
In relational databases, the relationship between data files is relational. Hierarchical
and network 54 databases require the user to pass a hierarchy in order to access
needed data. These databases connect to the data in different files by using common
data numbers or a key field. Data in relational databases is stored in different access
control tables, each having a key field that mainly identifies each row. In the
relational databases are more reliable than either the hierarchical or network database
structures. In relational databases, tables or files filled up with data are called relations
(tuples) designates a row or record, and columns are referred to as attributes or fields.
Relational databases work on each table has a key field that uniquely indicates each
row, and that these key fields can be used to connect one table of data to another.
4) Object-Oriented Model:
In this Model we have to discuss the functionality of the object oriented Programming
.It takes more than storage of programming language objects. Object DBMS's
increase the semantics of the C++ and Java .It provides full-featured database
programming capability, while containing native language compatibility. It adds the
database functionality to object programming languages.This approach is the
analogical of the application and database development into a constant data model and
language environment. Applications require less code, use more natural data
modeling, and code bases are easier to maintain. Object developers can write
13 Prepared By: Dr. Vipul Vekariya
complete database applications with a decent amount of additional effort. The object-
oriented database derivation is the integrity of object-oriented programming language
systems and consistent systems. The power of the object-oriented databases comes
from the cyclical treatment of both consistent data, as found in databases, and
transient data, as found in executing programs
4. Security management.
The DBMS creates a security system that enforces user security and data privacy. Security
rules determine which users can access the database, which data items each user can access,
and which data operations (read, add, delete, or modify) the user can perform. This is
especially important in multiuser database systems.
2) DISNTINCT
The SELECT DISTINCT statement is used to return only distinct (different) values. In a
table, a column may contain many duplicate values; and sometimes you only want to list the
different (distinct) values.
The DISTINCT keyword can be used to return only distinct (different) values.
3) WHERE
The WHERE clause is used to extract only those records that fulfill a specified criterion.
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
The AND & OR operators are used to filter records based on more than one condition.
The AND operator displays a record if both the first condition AND the second condition are
true.
The OR operator displays a record if either the first condition OR the second condition is
true.
5) ORDER BY
The ORDER BY keyword is used to sort the result-set by one or more columns.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records
in a descending order, you can use the DESC keyword.
6) INSERT INTO
The first form does not specify the column names where the data will be inserted, only their
values:
7) UPDATE
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE condition;
UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';
8) DELETE
The SELECT TOP clause is used to specify the number of records to return.
SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number;
SELECT *
FROM Persons
WHERE ROWNUM <=5;
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;
The following SQL statement selects all customers with a City starting with "ber":
The following SQL statement selects all customers with a City starting with "L", followed by
any character, followed by "n", followed by any character, followed by "on":
The following SQL statement selects all customers with a City starting with "b", "s", or "p":
The following SQL statement selects all customers with a City starting with "a", "b", or "c":
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...);
The following SQL statement selects all customers with a City of "Paris" or "London":
The BETWEEN operator selects values within a range. The values can be numbers, text, or
dates.
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
The following SQL statement selects all products with a price BETWEEN 10 and 20:
NOT BETWEEN
To display the products outside the range of the previous example, use NOT BETWEEN:
The following SQL statement selects all products with a price BETWEEN 10 and 20, but
products with a CategoryID of 1,2, or 3 should not be displayed:
SQL aliases are used to give a database table, or a column in a table, a temporary name.
Basically aliases are created to make column names more readable.
SELECT column_name(s)
FROM table_name AS alias_name;
Create new table from existing table with transfer of all structure of existing table with data.
Option 3: Create table tablename as select * from tablename where ‗1‘=‘2‘; (without data)
The INSERT INTO SELECT statement selects data from one table and inserts it into an
existing table. Any existing rows in the target table are unaffected.
The CREATE TABLE statement is used to create a table in a database. Tables are organized
into rows and columns; and each table must have a name.
The column_name parameters specify the names of the columns of the table.
The data_type parameter specifies what type of data the column can hold (e.g.
varchar, integer, decimal, date, etc.).
The size parameter specifies the maximum length of the column of the table.
The empty table can be filled with data with the INSERT INTO statement.
17) ALTER
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
Example:
19) DELETE
20) TRUNCATE
if we only want to delete the data inside the table, and not the table itself Then, use the
TRUNCATE TABLE statement:
Auto-increment allows a unique number to be generated when a new record is inserted into a
table.
The code above creates a sequence object called seq_person, that starts with 1 and will
increment by 1. It will also cache up to 10 values for performance. The cache option specifies
how many sequence values will be stored in memory for faster access.
To insert a new record into the "Persons" table, we will have to use the nextval function (this
function retrieves the next value from seq_person sequence):
The SQL statement above would insert a new record into the "Persons" table. The "ID"
column would be assigned the next number from the seq_person sequence. The "FirstName"
column would be set to "Lars" and the "LastName" column would be set to "Monsen".
22) VIEW
A view contains rows and columns, just like a real table. The fields in a view are fields from
one or more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a view and present the data as
if the data were coming from one single table.
1) Create View
2) UPDATE VIEW
CREATE OR REPLACE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
How do we select only the records with NULL values in the "Address" column? We will
have to use the IS NULL operator:
IS NOT NULL
1) PRIMARY KEY
The PRIMARY KEY constraint uniquely identifies each record in a database table.
Primary keys must contain UNIQUE values.
A primary key column cannot contain NULL values.
Most tables should have a primary key, and each table can have only ONE primary
key.
2) FOREIGN KEY
3) Unique Key
4) NOT NULL
The NOT NULL constraint enforces a column to NOT accept NULL values.
The NOT NULL constraint enforces a field to always contain a value. This means that
you cannot insert a new record, or update a record without adding a value to this field.
The CHECK constraint is used to limit the value range that can be placed in a column.
If you define a CHECK constraint on a single column it allows only certain values for
this column.
If you define a CHECK constraint on a table it can limit the values in certain columns
based on values in other columns in the row.
INNER JOIN: Returns all rows when there is at least one match in BOTH tables
LEFT JOIN: Return all rows from the left table, and the matched rows from the
right table
RIGHT JOIN: Return all rows from the right table, and the matched rows from
the left table
FULL JOIN: Return all rows when there is a match in ONE of the tables
1) INNER JOIN
The INNER JOIN keyword selects all rows from both tables as long as there is a match
between the columns in both tables.
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
The following SQL statement will return all customers with orders:
The SQL NATURAL JOIN is a type of EQUI JOIN and is structured in such a way that,
columns with same name of associate tables will appear once only.
- The associated tables have one or more pairs of identically named columns.
- The columns must be the same data type.
- Don‘t use ON clause in a natural join.
SELECT *
FROM table1
NATURAL JOIN table2;
SELECT *
FROM foods
NATURAL JOIN company;
3) OUTER JOIN
It is similar to inner join but give a bit more flexibility when selecting the data.
This type of join can be used in situations where it desired.
This is used when you select the data from left (right or both).
It selects the values in common and enter NULL where data is missing.
The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows
in the right table (table2). The result is NULL in the right side when there is no match.
SELECT column_name(s)
FROM table1
LEFT OUTER JOIN table2
ON table1.column_name=table2.column_name;
The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching
rows in the left table (table1). The result is NULL in the left side when there is no match.
SELECT column_name(s)
FROM table1
RIGHT OUTER JOIN table2
ON table1.column_name=table2.column_name;
The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the
right table (table2).The FULL OUTER JOIN keyword combines the result of both LEFT and
RIGHT joins.
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
1) AVG ( )
The following SQL statement gets the average value of the "Price" column from the
"Products" table
2) COUNT( )
The COUNT() function returns the number of rows that matches a specified criteria.
The following SQL statement counts the number of orders from "CustomerID"=7 from
the "Orders" table:
3) MAX( )
The MAX() function returns the largest value of the selected column.
The following SQL statement gets the largest value of the "Price" column from the
"Products" table:
4) MIN( )
The MIN() function returns the smallest value of the selected column.
The following SQL statement gets the smallest value of the "Price" column from the
"Products" table:
SELECT MIN(Price) AS SmallestOrderPrice FROM Products;
5) SUM( )
The SUM() function returns the total sum of a numeric column.
SELECT SUM(column_name) FROM table_name;
The following SQL statement finds the sum of all the "Quantity" fields for the
"OrderDetails" table:
SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;
GROUP BY STATEMENT
The GROUP BY statement is used in conjunction with the aggregate functions to group the
result-set by one or more columns.
HAVING CLAUSE
The HAVING clause was added to SQL because the WHERE keyword could not be used
with aggregate functions.
Select count(*), city from client_master group by city having count(*) >=4;
COMMIT
Commit command is used to permanently save any transaaction into database.
Rollback command
This command restores the database to last committed state. It is also use with savepoint
command to jump to a savepoint in a transaction.
Savepoint command
savepoint command is used to temporarily save a transaction so that you can rollback to that
point whenever necessary.
GRANT/REVOKE PRIVILEGES
This Oracle tutorial explains how to grant and revoke privileges in Oracle with syntax and
examples.
DESCRIPTION
You can GRANT and REVOKE privileges on various database objects in Oracle. We'll first
look at how to grant and revoke privileges on tables and then how to grant and revoke
privileges on functions and procedures in Oracle.
Syntax
The syntax for granting privileges on a table in Oracle is:
privileges
The privileges to assign. It can be any of the following values:
Privilege Description
SELECT Ability to perform SELECT statements on the table.
INSERT Ability to perform INSERT statements on the table.
UPDATE Ability to perform UPDATE statements on the table.
DELETE Ability to perform DELETE statements on the table.
REFERENCES Ability to create a constraint that refers to the table.
Ability to perform ALTER TABLE statements to change the table
ALTER
definition.
Object
The name of the database object that you are granting privileges for. In the case of granting
privileges on a table, this would be the table name.
User
Example
Let's look at some examples of how to grant privileges on tables in Oracle.
For example, if you wanted to grant SELECT, INSERT, UPDATE, and DELETE privileges
on a table called suppliers to a user name smithj, you would run the following GRANT
statement:
GRANT SELECT, INSERT, UPDATE, DELETE ON suppliers TO smithj;
You can also use the ALL keyword to indicate that you wish ALL permissions to be granted
for a user named smithj.
For example:
If you wanted to grant only SELECT access on your table to all users, you could grant the
privileges to the public keyword. For example:
T1 T2
1. read(A)
2. A := A – 50
3. write(A)
read(A), read(B), print(A+B)
4. read(B)
5. B := B + 50
6. write(B
Serial: The transactions are executed one after another, in a non-preemptive manner.
Concurrent: The transactions are executed in a preemptive, time shared method.
Advantage of concurrent transction:
o increased processor and disk utilization, leading to better transaction
throughput
E.g. one transaction can be using the CPU while another is reading
from or writing to the disk
o Reduced average response time for transactions: short transactions need not
wait behind long ones.
Let us consider there are two transactions T1 and T2, whose instruction sets are given as
following.
T1
Read A;
A = A – 100;
Write A;
Read B;
B = B + 100;
Write B;
T2
Read A;
Temp = A * 0.1;
Read C;
C = C + Temp;
Write C;
T1 T2
Read A;
A = A - 100;
Write A;
Read A;
Temp = A * 0.1;
Read C;
C = C + Temp;
Write C;
Read B;
B = B + 100;
Write B;
Conflict serializability
We are unable to swap instructions in the above schedule to obtain either the serial
schedule < T3, T4 >, or the serial schedule < T4, T3 >.
View Serializabiltiy
Let S and S´ be two schedules with the same set of transactions. S and S´ are view
equivalent if the following three conditions are met, for each data item Q,
Neither T3 nor T4 can make progress — executing lock-S(B) causes T4 to wait for T3
to release its lock on B, while executing lock-X(A) causes T3 to wait for T4 to release
its lock on A.
T1 T2
Lock-X(P) Lock- S(Q)
Read(P) Read(Q)
P= P – 100 Unlock(Q)
Write(P) Lock- S(P)
Unlock(P) Read(P)
Lock-X(Q) Unlock(P)
Read(Q) Display(P + Q)
Q= Q + 100
Write(Q)
Unlock(Q)
Rigorous two-phase locking is even stricter: here all locks are held till commit/abort.
In this protocol transactions can be serialized in the order in which they commit.
In above schedule we swapped the one instruction in transaction T2 and we avoid the
deadlock but after this situation above schedule is not more concurrent.
So we have to improve the concurrency using some technique this is called lock
upgrdation protocol.
Each transaction is issued a timestamp when it enters the system. If an old transaction
Ti has time-stamp TS(Ti), a new transaction Tj is assigned time-stamp TS(Tj) such that
TS(Ti) <TS(Tj).
The protocol manages concurrent execution such that the time-stamps determine the
serializability order.
In order to assure such behavior, the protocol maintains for each data Q two
timestamp values:
The timestamp ordering protocol ensures that any conflicting read and write
operations are executed in timestamp order.
System is deadlocked if there is a set of transactions such that every transaction in the set is
waiting for another transaction in the set.
Deadlock prevention protocols ensure that the system will never enter into a deadlock state.
Some prevention strategies :
a. Require that each transaction locks all its data items before it begins execution
(predeclaration).
b. Impose partial ordering of all data items and require that a transaction can lock
data items only in the order specified by the partial order (graph-based
protocol).
Following schemes use transaction timestamps for the sake of deadlock prevention alone.
older transaction may wait for younger one to release data item. Younger
transactions never wait for older ones; they are rolled back instead.
a transaction may die several times before acquiring needed data item
n Timeout-Based Schemes:
a transaction waits for a lock only for a specified amount of time. After that,
the wait times out and the transaction is rolled back.
Some transaction will have to rolled back (made a victim) to break deadlock.
Select that transaction as victim that will incur minimum cost.
Before Ti executes write(X), a log record <Ti, X, V1, V2> is written, where V1 is the value
of X before the write (the old value), and V2 is the value to be written to X (the new value).
When Ti finishes it last statement, the log record <Ti commit> is written.
Output of updated blocks to stable storage can take place at any time before or after
transaction commit Order in which blocks are output can be different from the order
in which they are written.
1) Explain Select, Project, Union, set intersection and set difference operation in
relational algebra.
1) Selection
Notation: p(r)
p is called the selection predicate
branch_name=“Perryridge”(account)
branch_name=“Perryridge” ^ amount > 1200 (account)
2) Project
Notation:
A1 , A2 ,, Ak (r )
The result is defined as the relation of k columns obtained by erasing the columns that
are not listed
loan_number,amount (loan)
3) Union
Notation: r s
Defined as: r s = {t | t r or t s}
4) Set Difference
Notation r – s
Defined as: r – s = {t | t r and t s}
Set differences must be taken between compatible relations.
r and s must have the same arity
attribute domains of r and s must be compatible
Notation r – s
Defined as:
r – s = {t | t r and t s}
5) Set intersection
Notation: r s
Assume:
Notation: r s
2) If tr and ts have the same value on each of the attributes in R S, add a tuple t
to the result, where
Find the name of all customers who have a loan at the bank and the loan amount
customer_name, loan_number, amount (borrower loan)
Computes the join and then adds tuples form one relation that does not match tuples
in the other relation to the result of the join.
Attribute types:
Derived attributes
1. One to one
2. One to many
3. Many to one
4. Many to many
We express cardinality constraints by drawing either a directed line (), signifying
―one,‖ or an undirected line (—), signifying ―many,‖ between the relationship set and
the entity set.
One-to-one relationship:
A customer is associated with at most one loan via the relationship borrower
In the one-to-many relationship a loan is associated with at most one customer via
borrower, a customer is associated with several (including 0) loans via borrower
An entity set that does not have sufficient attribute to form a primary key is referred to
as a weak entity set.
The existence of a weak entity set depends on the existence of a identifying entity set
The discriminator (or partial key) of a weak entity set is the set of attributes that
distinguishes among all the entities of a weak entity set.
The primary key of a weak entity set is formed by the primary key of the strong entity
set on which the weak entity set is existence dependent, plus the weak entity set‘s
discriminator.
Top-down design process; we designate sub groupings within an entity set that are
distinctive from other entities in the set.
Specialization is the process of identifying the subset of entity set( the superclass or
supertype) that share some distinguishing characteristics.
These sub groupings become lower-level entity sets that have attributes or participate
in relationships that do not apply to the higher-level entity set.
Depicted by a triangle component labeled ISA (E.g. customer ―is a‖ person).
Generalization:
A bottom-up design process – combine a number of entity sets that share the same
features into a higher-level entity set.
Specialization and generalization are simple inversions of each other; they are
represented in an E-R diagram in the same way.
Generalization is a process in which multiple entity set are synthesized into higher
level entity set on the basis of common future.
For example the customer and employee have some common future like name, city,
street then using generalization we give the person attribute.
Higher level entity set also may be designated by the terms superclass and subclass.
Advantage:
This adds more semantic content and information to the design in concise form.
DECLARE
N NUMBER(3):=1;
S NUMBER(4):=0;
BEGIN
WHILE N <=100
LOOP
S:=S+N;
N:=N+2;
END LOOP;
END;
DECLARE
N NUMBER(5):=&N;
S NUMBER:=0;
R NUMBER(2):=0;
BEGIN
WHILE N !=0
LOOP
R:=MOD(N,10);
S:=S+R;
N:=TRUNC(N/10);
END LOOP;
END;
The oracle engine use a work area for its internal processing in order to execute an
SQL statement.
Oracle has pre-defined area in main memory in which cursor are opened.
Cursors are classified depending on the circumstance under which they are opened.
If the oracle engine opened a cursor for its internal processing it is known as implicit
cursor.
A cursor can also opened for processing data through PL/SQ block, on demand such
a user defined cursor known as explicit cursor.
Cursor is like a temporary area where you can process fetch the records and process
then individually as required
Stored procedure is a group of SQL statements that form a logical unit and perform a
particular task.
Stored procedure has been pre-compiled and stored in oracle engine‘s system table (
data dictionary).
They define a programming interface for the database rather than allowing the client
application to interact with database objects directly.
Stored procedures are typically used for data validation or to encapsulate large,
complex processing instructions that combine several SQL queries.
Precompiled execution. SQL Server compiles each stored procedure once and then
reutilizes the execution plan. This results in tremendous performance boosts when
stored procedures are called repeatedly.
Enhanced security controls. You can grant users permission to execute a stored
procedure independently of underlying table permissions
Unlike the stored procedure and functions, which have to be called explicitly, the
database triggers are fires (executed) or called implicitly .
To audit the process. For example, to keep track of changes made to a table.
Types of Trigger.
Row-level Trigger
A row trigger is fired once for each row that is affected by DML command. For
example, if an UPDATE command updates 100 rows then row-level trigger is fired
100 times.
Row-level trigger are used to check for the validity of the data. They are typically
used to implement rules that cannot be implemented by integrity constraints.
Before Triggers
While defining a trigger, you can specify whether the trigger is to be fired before the
command (INSERT, DELETE, and UPDATE) is executed or after the command is
executed.
Before triggers are commonly used to check the validity of the data before the action
is performed. For instance, you can use before trigger to prevent deletion of row if
deletion should not be allowed in the given case.
AFTER Triggers
After triggers are fired after the triggering action is completed. For example, If after
trigger is associated with INSERT command then it is fired after the row is inserted
into the table.
For example, the following trigger is fired only when perk is more than 500.
BEGIN
END;
All these data might not be necessary all the time whenever we use those tables. So, a better option is to
split up the bulk table into small parts and use only those tables which suit the actual purpose at a given
instance of time. In this way, redundancy is reduced. To make the long story short, we can simply say that
normalization is a process of dividing a big table into smaller ones in order to reduce redundancy.
Normalization Avoids
Duplication of Data – The same data is listed in multiple lines of the database
Insert Anomaly – A record about an entity cannot be inserted into the table without first inserting
Information about another entity – Cannot enter a customer without a sales order
Delete Anomaly – A record cannot be deleted without deleting a record about a related entity.
Cannot delete a sales order without deleting all of the customer‘s information.
Update Anomaly – Cannot update information without changing information in many places. To
Update customer information, it must be updated for each sales order the customer has placed
A:
Insertion Anomaly
It is a failure to place information about a new database entry into all the places in the database
Where information about the new entry needs to be stored. In a properly normalized database,
Information about a new entry needs to be inserted into only one place in the database, in an
Inadequately normalized database, information about a new entry may need to be inserted into
more than one place, and human fallibility being what it is, some of the needed additional
insertions may be missed.
Deletion anomaly
It is a failure to remove information about an existing database entry when it is time to remove
that entry. In a properly normalized database, information about an old, to-be-gotten-rid-of entry
needs to be deleted from only one place in the database, in an inadequatly normalized database,
information about that old entry may need to be deleted from more than one place.
Update Anomaly
An update of a database involves modifications that may be additions, deletions, or both. Thus
―update anomalies‖ can be either of the kinds discussed above. All three kinds of anomalies are
highly undesirable, since thier occurence constitutes corruption of the database. Properly
normalized database are much less susceptible to corruption than are unnormalized databases.
First normal form (1NF) sets the very basic rules for an organized database:
4627 38 60.20
3214 20 17.50
4627 30 60.20
After Conversion of above unormaized relation in to 1st normal form. Below table is
in 1st normal form.
If the key attributes has more than one attributes then non key attribute should be
functionally dependant on part of the key attribute.
After 2nd normal form below are the tables. It is divided in to 3 tables.
A: A DBMS offers two main approaches to access control. Discretionary access control is
based on the concept of access rights, or privileges, and mechanisms for giving users such
privileges. A privilege allows a user to access Borne data object (e.g., to read or Modify). A
user, who creates a database object such as a table or a vie\v automatically, gets all applicable
privileges on that object.
Mandatory access control is based on system wide policies that cannot be changed by
individual users. In this approach each databal.'3e object is assigned a security class, each
user is assigned clearance for a security class, and rules are imposed on reading and writing
of database objects by users.
For our purposes object is either a base table or a views. Several privileges can be specified,
Including these:
SELECT: The right to access (read) all columns of the table specified as the object,
including columns added later through ALTER TABLE commands.
INSERT( column-name): The right to insert rows with (non-null or non default) values
in the column of the table named as object. If this right is to be granted with respect to all
columns, including columns that might be added later, we can simply use INSERT. The
privileges UPDATE( column name) and UPDATE are similar.
DELETE: The right to delete rows from the table named as object.
REFERENCES(column-name): The right to define foreign keys (in other tables) that
refer to the specified column of the table object. REFERENCES without a column name
specified denotes this right with respect to all columns, including any that are added later.
The Bell-La Padula model imposes two restrictions on all reads and writes of database
objects:
1) Simple Security Property: Subject S is allowed to read object 0 only if class(8) > class
(()). For example, a user with TS clearance can read a table with C clearance, but a user with
C clearance is not allowed to read a table with TS classification.
2) *-Property: Subject S is allowed to write object 0 only if class(S) <class (O). For
example, a user with S clearance can write only objects with S or TS classification.
CHAPTER-2
1) A superkey is a set of one or more attributes that, taken collectively, allow us to
identify uniquely a tuple in relation.
2) Candidate key is a minimal superkey for which no proper subset is a superkey.
3) Primary key is a chosen candidate key that is chosen by the database designer as
the principal means of identifying tuples within a relation.
4) A query language is a language in which a user requests information from database.
5) A database schema, along with primary key and foreign key dependencies, can be
depicted pictorially by schema diagram.
6) The relation algebra defines a set of algebraic operations that operate on tables and
output tables as their results.
7) Null value signifies that the value is unknown or does not exist.
8) A domain is set of values that are allowed to keep for attributes.
9) A Tuple is term to signify rows.
10) A tuple variable is a variable whose domain is set of all tuples.
11) Database schema is the logical design of database.
12) Database instance is a snapshot of data in a database at a given instant in time.
13) In procedural language, user instructs the system to perform a sequence of
operations on the database to compute the desired result.
CHAPTER - 6
1. An entity is an object that exists and is distinguishable from other objects.
a. Example: specific person, company, event, plant
2. A relationship is an association among several entities
3. A relationship set is a mathematical relation among n 2 entities, each taken from
entity sets
a. {(e1, e2, …en) | e1E1, e2E2, …, enEn}
4. Degree of relationship is number of entity sets that participate in a relationship set.
5. Domain – the set of permitted values for each attribute
6. An entity is represented by a set of attributes that is descriptive properties
possessed by all members of an entity set.
7. Mapping Cardinality-it express the number of entities to which another entity can
be associated via a relationship set.
8. A super key of an entity set is a set of one or more attributes whose values uniquely
determine each entity.
9. A candidate key of an entity set is a minimal super key: Customer_id is candidate key
of customer,account_number is candidate key of account
10. Although several candidate keys may exist, one of the candidate keys is selected to
be the primary key.
11. Total participation (indicated by double line): every entity in the entity set
participates in at least one relationship in the relationship setE.g. participation of
loan in borrower is total every loan must have a customer associated to it via
borrower
12. Partial participation: some entities may not participate in any relationship in the
relationship setExample: participation of customer in borrower is partial
13. The discriminator(or partial key) of a weak entity set is the set of attributes that
distinguishes among all the entities of a weak entity set
14. The process of designating subgroupings within an entity set is called specialization.
15. Generalization is a process in which multiple entity set are synthesized into higher
level entity set on the basis of common feature.
16. Aggregation is an abstraction through which relationship are treated as higher level
entities.
17. Normalization-process of removing redundant data and ensuring data dependency.
PL/SQL
1. Cursor-The oracle engine use a work area for its internal processing in order to
execute an SQL statement. This work area is private to SQL operation is called cursor.
2. The data is stored into cursor is called active data set.
3. A database trigger is procedural code that is automatically executed in response to
certain events on a particular table in a database.
4. A row trigger is fired once for each row that is affected by DML command.
5. Statement Level Trigger: It is fired once on behalf of the triggering statement,
independent on number of rows the triggering statements affect.
Query Processing
1. Query processing – refers to the range of activities involved in extracting data from a
database.
2. A relational algebra operation annotated with instruction on how to evaluate is
called evaluation primitive.
3. Query optimization is process of selecting the most efficient query-evaluation plan
from among the many strategies usually possible for processing a given query
especially if the query is complex.