Download rdbms - Career Varsity

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

SQL wikipedia , lookup

Serializability wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

PL/SQL wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Database wikipedia , lookup

Concurrency control wikipedia , lookup

Clusterpoint wikipedia , lookup

Versant Object Database wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
RDBMS
1. Why would you choose a database system instead of simply storing data in
operating system files? When would it make sense not to use a database
system.
Files in operating system refers to string of characters.
Files in DBMS refers to collection of records.
S.No
1.
Points of
distinction
Main memory
storage limit
2.
Retrieval
complexity
3.
Searching
complexity
4.
Data
Inconsistency
5.
Crash Recovery
6.
Security
Mechanism
7.
Volume of data
and no of users
use
File Systems
DBMS
Limited memory to store and hold
data.
Secondary storage devices are
used to hold data and relevant
parts are to be loaded into main
memory for processing as needed.
More memory to store and
hold data.
Internal storage
mechanisms need not be
revealed to the user.
Relevant parts of data are
automatically loaded into
main memory for
processing as needed.
Automatic commands and
utilities are available to
retrieve data.
A user has to write special
programs to answer each question
a user may want to ask about
data.
Searching complexity is more
because of the large volume of
data to be searched.
The user must protect data from
inconsistent changes made by
different users while accessing the
data concurrently.
The user must ensure that data is
restored to a consistent state if the
system crashes while changes are
being made.
Operating systems provide only a
password mechanism for security
for files. This is not sufficiently
flexible to enforce security policies
in which different users have
permission to access different
subsets of data.
As the volume of data and number
of users grow – hundreds of
gigabytes of data and thousands of
users file system is complex and
unable to manage
Searching complexity is
less because efficient
searching technique is
adopted by DBMS itself.
Data Integrity is
maintained automatically
by DBMS itself.
DBMS protects users from
the effects of system
failures.
DBMS provides more
security measures by
centralizing the
administration of data
when several users share
the data .
As the volume of data and
number of users grow –
hundreds of gigabytes of
data and thousands of
users DBMS is efficient to
manage Corporate
databases.
When the user should not use a DBMS :



A DBMS should be used only for answering complex queries or handling many
concurrent requests. It is not suitable for certain specialized applications with tight
real-time constraints or applications with just a few well-defined critical operations
for which efficient custom code must be written.
An application sometimes may need to manipulate the data in ways that are not
supported by the query language. In such cases, DBMS is not used. Eg. Relational
databases do not support flexible analysis of text data.
If specialized performance or data manipulation requirements are central to an
application, the application may choose not to use a DBMS.
2. What are the Integrity Constraints supported by RDBMS?

Integrity Constraints are the set of constructs provided by a data model for
specifying conditions that must be satisfied by the data.

An Integrity constraint (IC) is a condition specified on a database schema
and restricts the data that can be stored in an instance of the database.

Integrity constraints can be
Domain Constraints
Key Constraints
Foreign Key Constraints
General Constraints




Domain Constraints


Domain refers to a set of possible values for each attribute
associated with an entity set.
Domain constraints in the schema specify an important condition
that the user wants each instance of the relation to satisfy.
Key Constraints

A Key Constraint is a statement that a certain minimal subset of
the fields of a relation is a unique identifier for a tuple.

Super Key : It is a set of one or more attributes which put
together enable us to identify uniquely an entity in the entity set.

Candidate Key : A set of fields that uniquely identifies a tuple
according to a key constraint is called a candidate key. A superkey
for which no subset is a superkey is called a candidate key. ( A
superkey that is minimal is a candidate key ) Eg. In students
relation, sid is candidate key.

Primary Key : It is a candidate key (there may be more than one)
chosen by the database designer to identify entities in an entity
set.
Foreign Key Constraints


The most common IC involving two relations is a foreign key
constraint.
Foreign Key : If the primary key of one table is referenced in the
other table, then that key is called as foreign key in the another
table. The foreign key in the referencing relation must match the
primary key of the referenced relation.
General Constraints


General constraints : Domain, primary key and foreign key
constraints are considered to be a fundamental part of the
relational data model. It is also necessary to specify more general
constraints.
General constraints are
o Table Constraints – Table constraints are associated with
a single table and checked whenever the table is modified.
o Assertions – Assertions involve several tables and are
checked whenever any of these tables is modified.
3. Discuss the strengths and weaknesses of the trigger mechanism.
triggers with other integrity constraints supported by SQL.
Contrast

A Trigger is a procedure that is automatically invoked by the DBMS in
response to specified changes to the database, and is typically specified by
the DBA.

A database that has a set of associated triggers is called an active database.

A trigger description contains three parts :
 Event : A change to the database that activates the trigger.
 Condition : A query or test that is run when the trigger is
activated
 Action : A procedure that is executed when the trigger is
activated and its condition is true.
Strengths of Triggers
 A trigger functions as a ‘daemon’ that monitors a database.
 Triggers offer a powerful mechanism for dealing with changes to a
database.
Weaknesses of Triggers
 Though Triggers are powerful, they must be used with caution.
 Triggers can be hard to understand.
 The effect of a collection of triggers can be very complex, and
maintaining an active database can become very difficult.
 A judicial use of integrity constraints can replace the use of
triggers.


S.No
1
Points of
distinction/
similarity
Use
2
Property
3
Activation
4
Integrity
Maintenance
5
Potential
uses
6
Auditing
information
Constraints
The meaning of a constraint is
not defined operationally,
unlike the effect of a trigger.
Constraints are easier to
understand and gives DBMS
more opportunities to optimize
execution.
A constraint prevents data
from being made inconsistent
by any kind of statement. (This
restriction makes a constraint
easier to understand)
Less flexible
Triggers
The common use of
triggers is to maintain
database consistency.
Triggers are hard to
understand.
A trigger is activated by a
specific kind of statement.
Triggers allow the user to
maintain database integrity
in more flexible ways.
The potential uses of
triggers goes beyond
integrity maintenance.
Triggers can alert users to
unusual events.
Triggers can generate a log
of events to support
auditing and security
checks.
4. Why are stored procedures important? How do we declare stored
procedures and how are they called from application code?








A stored procedure is a program that is executed through a single SQL
statement that can be locally executed and completed within the process
space of the database server.
The results can be packaged into one big result and returned to the
application or the application logic can be performed directly at the server,
without having to transmit the results to the client at all.
Stored procedures are also beneficial for software engineering reasons.
Once a stored procedure is registered with the database server, different
users can re-use the stored procedure, eliminating duplication of efforts in
writing SQL Queries or application logic, and making code maintenance easy.
The application programmers do not need to know the database schema if
they encapsulate all database access into stored procedures.
Although they are called stored procedures, they do not have to be
procedures in a programming language sense, they can be functions.
Creating a Simple Stored procedure :
 Stored procedures must have a name.
 Stored procedures may or may not have parameters.
Creating a procedure in PL/SQL :


A procedure is a subprogram that performs a specific
action.
The general syntax of PL/SQL procedure is
[CREATE [OR REPLACE]]
PROCEDURE procedure_name[(parameter[, parameter]...)]
[AUTHID {DEFINER | CURRENT_USER}] {IS | AS}
[PRAGMA AUTONOMOUS_TRANSACTION;]
[local declarations]
BEGIN
executable statements
[EXCEPTION
exception handlers]
END [name];
where parameter stands for the following syntax:
parameter_name [IN | OUT [NOCOPY] | IN OUT [NOCOPY]] datatype
[{:= | DEFAULT} expression]
 Calling procedures :
 Procedures can be called in an interactive SQL with the
CALL statement.
 The general syntax is
CALL procedurename(arg1,arg2,……..argn)
 Creating a function in PL/SQL :
 A function is a subprogram that computes a value.
Functions and procedures are structured alike, except that
functions have a RETURN clause.

The general syntax of PL/SQL function is
[CREATE [OR REPLACE]]
FUNCTION function_name[(parameter[, parameter]...)] RETURN datatype}
[AUTHID {DEFINER | CURRENT_USER}]
[PARALLEL_ENABLE]
[DETERMINISTIC] {IS | AS}
[PRAGMA AUTONOMOUS_TRANSACTION;]
[local declarations]
BEGIN
executable statements
[EXCEPTION
exception handlers]
END [name];

Calling functions :
 Functions can be called in an interactive SQL with the CALL
statement.
 The general syntax is
Variable name := CALL functionname(arg1,arg2,……..argn)
5. What is a three-tier architecture? What advantages does it offer over singletier and two-tier architectures? Give a short overview of the functionality at
each of the three tiers.
 The predecessors of three-tier architectures are single-tier and client-server
architectures.

In a Single-Tier Architecture the data-intensive applications were combined
into a single tier, including the DBMS, application logic, and user interface.
 Two-Tier Architectures are also referred to as Client-Server Architectures,
consisting of a client computer and a server computer, which interact through
a well-defined protocol.
 Three-Tier Architecture also separates application logic from data
management. The three tiers are
 Presentation Tier : Users require a natural interface to make
requests, provide input, and to see results. Web-based interfaces
are popular
 Middle Tier : The application logic executes here. An application is
coded in general-purpose languages such as C++ or Java
 Data Management Tier : Data-intensive Web applications involve
DBMSs
Architecture
Advantages
Disadvantages
Single-Tier
 The application typically ran on
 Users expect graphical
Architecture
a mainframe, and users accessed
interfaces that require much
it through dumb terminals that
more computational power than
could perform only data input
simple dumb terminals
and display
 Do not scale thousands of users
 Easily maintained by a central
administrator
Two –Tier
 The client implements just a
 The thick-client model has
Architecture
graphical user interface and are
several disadvantages when
often called as thin clients (Eg.
compared to thin-client model
Web browsers)
o There is no central place
 The server implements both the
to update and maintain
business logic and the data
the business logic
management.
o A large amount of trust is
(VB, Powerbuilder)
required between the
 Powerful clients that implement
server and the clients
both user interface and business
o Does not scale with the
logic are often called as thick
number of clients
clients.
(Cannot handle more
 Two-Tier Architectures physically
than few hundred clients)
separate the user interface from
o Do not scale as the
the data management layer
application accesses
 Implementing Two-Tier
more and more database
Architectures, does not require
systems
to have dumb terminals on the
client side
Three-Tier
 Heterogeneous Systems :

Architecture
Applications can utilize the
strengths of different platforms
and different software
components at the different
tiers. Easy to modify or replace
the code at any tier without
affecting other tiers
 Thin Clients : Web Browsers
 Integrated Data Access : The
data can be managed from
several sources
Scalability to many clients :
Each client is lightweight and all
access to the system is through
the middle tier
 Software Development
Benefits : The application is
clearly divided into parts
o Address presentation
o Data access
o Business logic
Each application tier can be built out
of reusable components that can be
individually developed, debugged
and tested

6.
What are ACID properties? Define Atomicity, Consistency, Isolation and
Durability and illustrate them through examples.
The ACID Properties

A transaction is an execution of a user program, seen by the DBMS as a series
of read and write operations.

A DBMS must ensure four important properties to maintain data in the face of
concurrent access and system failures:

ACID properties : Atomicity, Consistency, Isolation, Durability
 Atomicity : Users should be able to regard the execution of each
transaction as atomic : Either all transactions are carried out or none are.
Users should not have to worry about the effect of incomplete transactions
(when a system crash occurs).
 Consistency :
Each transaction, run by itself with no concurrent
execution of other transactions, must preserve the consistency of the
database.
The DBMS assumes that consistency holds for each
transaction. Ensuring this property of a transaction is the responsibility of
the user.
 Isolation : Users should be able to understand a transaction without
considering the effect of other concurrently executing transactions, even if
the DBMS interleaves the actions of several transactions for performance
reasons. This property is sometimes referred to as isolation. Transactions
are isolated, or protected, from the effects of concurrently scheduling
other transactions.
 Durability : Once the DBMS informs the user that a transaction has been
successfully completed, its effects should persist even if the system
crashes before all its changes are reflected on disk. This property is called
durability.
7. What does the lock manager do? Describe the lock table and transaction
table data structures and their role in lock management.












A DBMS must be able to ensure that only serializable, recoverable schedules are
allowed and that no actions of committed transactions are lost while undoing
aborted transactions.
A DBMS typically uses a locking protocol to achieve this.
A lock is a small bookkeeping object associated with a database object.
A lock is a mechanism used to control access to database object.
Two kinds of locks are commonly supported by a DBMS :
 Shared locks : Shared locks on an object can be held by two different
transactions at the same time.
 Exclusive locks : Exclusive lock on an object ensures that no other
transactions hold any lock on this object.
A locking protocol is a set of rules to be followed by each transaction (and
enforced by the DBMS) to ensure that, even though actions of several
transactions might be interleaved, the net effect is identical to executing all
transactions in some serial order.
Eg. Every transaction begins by obtaining a shared lock on each data object
that it needs to read and an exclusive lock on each data object that it needs to
modify, then releases all its locks after completing all actions.
The part of the DBMS that keeps track of the locks issued to transactions is called
the lock manager.
The lock manager maintains a lock table, which is a hash table with the data
object identifier as the key,
The DBMS also maintains a descriptive entry for each transaction in a
transaction table, and among other things, the entry contains a pointer to a list
of locks held by the transaction.
This list is checked before requesting a lick, to ensure that a transaction does not
request the same lock twice.
A lock table entry for an object can be a page, a record and so on depending on
the DBMS. It contains the following information
 The number of transactions currently holding a lock on the
object. ( this can be more than one if the object is locked in
shared mode )
 The nature of the lock ( shared or exclusive)
 A pointer to a queue of lock requests.
8. Compare RDBMS with ORDBMS. Describe an application scenario for which
you would choose an RDBMS and explain why. Similarly, describe an
application scenario for which you would choose an ORDBMS and explain why.
S.No
1
2
RDBMS
Relational Database Management
Systems
Based on Relational Data Model
3
4
Dominant model
5
RDBMS support a small, fixed collection
of data types ( eg. Integers, dates,
ORDBMS
Object – Relational Database
Systems
Based on Object Data Model
(ODM)
Gaining popularity
ORDBMS is an attempt to extend
relational database systems to
provide a bridge between the
relational and object-oriented
paradigms.
ORDBMS is based on ObjectOriented Database systems and
strings ) which has proven adequate for
traditional application domains such as
administrative data processing
6
Supports Structured Query Language
( SQL )
7
RDBMS products :
 IBM’s DB2
 Informix
 Oracle
 Sybase
 Microsoft’s Access
 Fox Base
 Paradox
 Tandem
 Teradata
8
Supports Standard data types and
additional data types
9
Case Scenario :
9.
Relational Database systems and
are aimed at application domains
where complex objects play a
central role.
Supports Object Query Language
( OQL )
SQL : 1999 standard extends SQL
to incorporate support for the
object-relational model of data
Object-oriented model products:
 Objectstore
 Versant
Object-relational model products:
Used in DBMS products from
 IBM
 Informix
 Objectstore
 Oracle
 Versant
 Others
Supports standard data types and
new richer data types.
The new richer data types
supported are
 User-defined data types
that supports image, voice
and video footage and
these must be stored in
the database
 Inheritance data types to
inherit the commonality
between different types
(eg. To inherit some
features of image objects
while defining compressed
image objects and lowresolution image objects
 Object Identity data types
like references or pointers
to objects (eg video) for
giving objects a unique
object identity, which can
be used to refer or point
to them from elsewhere in
the data.
Case Scenario :
Compare the similarities and differences between OODBMS and ORDBMS.
In particular compare OQL and SQL : 1999 and discuss the underlying data
model.

OODBMS : Object-Oriented Database Management Systems



S.No
1
2
3
ORDBMS : Object-Relational Database Management Systems
Similarities
 Both supports user-defined ADTs, structured types, object identity
and reference types and inheritance.
 Both supports an extended form of SQL. OODBMS support
ODL/OQL. ORDBMS support an extended form of SQL.
 ORDBMS consciously try to add OODBMS features to an RDBMS
and OODBMS in turn have developed query language based on
relational query languages.
 Both provide DBMS functionality such as concurrency control and
recovery.
Differences
OODBMS
OODBMSs aim to achieve seamless
integration with a programming
language such as C++, Java.
An OODBMS is aimed at applications
where an object-centric viewpoint is
appropriate.
The query facilities of OQL are not
supported efficiently in most OODBMSs.
ORDBMS
Such integration is not an important
goal for an ORDBMS.
An ORDBMS is optimized for
applications in which large data
collections are the focus, even
though objects may have a rich
structure and be fairly large,
The query facilities are the
centerpiece of an ORDBMS.