DBMS Ctevt Students
DBMS Ctevt Students
UNIT-1
Data:
Data is a raw fact or unorganized form (such as
alphabets, numbers, or symbols) that refers to or
represent, condition, ideas or objects. Data is
limitless and present everywhere in the universe.
Information :
Data that
✓has been verified to be accurate and timely.
✓ Is specific and organized for a purpose.
✓Is represented within a context that gives it
meaning and relevance.
✓That can lead to an increase in
understanding and decrease in uncertainty
is called information.
flat file database
A flat file database is a database which is stored
on its host computer system as an ordinary
unstructured file called a "flat file". To access the
structure of the data and manipulate it, the file
must be read in its entirety into the computer's
memory. Upon completion of the database
operations, the file is again written out in its
entirety to the host's file system. In this stored
mode the database is said to be "flat", meaning
that it has no structure for indexing and there are
usually no structural relationships between the
records. A flat file can be a plain text file or
a binary file.
Database :
A database is a collection of information that is
organized so that it can easily be accessed
managed and update. There are two type of
database:
▪ Conventional Database: Collection of data without
use of DBMS. E.g. Telephone diary, register.
▪ Computerized database: The collection of data
with the help of computer and DBMS in the form of
data file is known as computerized database. The
types of computer systems that can run database
management system are Centralized PC and
Client/Server and distributed.
Elements of Database:
1. Field: Smallest unit of Database.
2. Record: A Collection of multiple related
fields.
3. Table: A collection of records or group of
records with the row and column order.
4. Tuple: A record row in the database.
5. Index: It is a process of organizing data in
specific order.
6. Cell: A cell is a inter section of rows and
columns.
Characteristics of database: A modern DBMS has
the following characteristics −
• Real-world entity − A modern DBMS is more
realistic and uses real-world entities to design
its architecture. It uses the behavior and
attributes too. For example, a school database
may use students as an entity and their age as
an attribute.
• Relation-based tables − DBMS allows entities
and relations among them to form tables. A
user can understand the architecture of a
database just by looking at the table names.
• Less redundancy − DBMS follows the rules of
normalization, which splits a relation when any of its
attributes is having redundancy in values.
Normalization is a mathematically rich and scientific
process that reduces data redundancy.
• Consistency − Consistency is a state where every
relation in a database remains consistent. There exist
methods and techniques, which can detect attempt of
leaving database in inconsistent state. A DBMS can
provide greater consistency as compared to earlier
forms of data storing applications like file-processing
systems.
• Query Language − DBMS is equipped with query
language, which makes it more efficient to retrieve and
manipulate data. A user can apply as many and as
different filtering options as required to retrieve a set
of data. Traditionally it was not possible where file-
processing system was used.
• Multiuser and Concurrent Access − DBMS supports multi-
user environment and allows them to access and
manipulate data in parallel. Though there are restrictions
on transactions when users attempt to handle the same
data item, but users are always unaware of them.
• Multiple views − DBMS offers multiple views for different
users. A user who is in the Sales department will have a
different view of database than a person working in the
Production department. This feature enables the users to
have a concentrate view of the database according to their
requirements.
• Security − Features like multiple views offer security to
some extent where users are unable to access data of other
users and departments. DBMS offers methods to impose
constraints while entering data into the database and
retrieving the same at a later stage.
Data base system :
The database, data collection with DBMS is called data
base system. A database system is a way of organizing
information on a computer, implemented by a set of
computer programs. This kind of organization should
offer:
o simplicity - an easy way to collect, access-connect, and
display information;
Data Models
Unit-2
Data model :
Data model is a collection of conceptual tools
used for describing data, data relationships
and data constraints. The model should enable
the designer to incorporate a major portion of
semantics of the database in the system.
E-R Diagram :
The overall logical structure of a database can be
expressed graphically by E-R diagram which
consist of following components :
- Rectangles, which represent entity sets.
- Ellipses, which represent attributes.
- Diamonds which represent relationships among
entity sets.
- Lines, which links attributes to entity sets and
entity set to relationship
Example :
E- No E- Name P-No P- Name
Address
Figure : E-R diagram for a part of the database of a
project management system entity set:
• An entity set is represented by a set of attributes.
Possible attributes of the employee entity set are
E_No, E_ Name and Address.
Attributes
Relation Databases
Unit3
Relational Database :-
A relational database consists of a collection of tables
i.e, in this model entity sets and relationships all are
represented by tables. A row in a table represents a
relationship among a set of values. Each row of a
relation (table) is called a tuple. Fig shows the
Structure of relational Database .
Table Name : student
attributes
Output:-
R U S= a b c
d c a
b f e
b c a
c d f
For example :
Borrower(customer_name,loan_no)
Depositor (customer_name ,Account_number)
List all the customers who have either an account
or loan number or both
Example :
Find the names of all customers who have an
account but not a loan numbers
Relational Algebra:
customer_name (Depositor )- customer_ name
(Borrower)
Output
R S= b f e
Example :
Borrow (customername, loan_number)
Depositor (customername, accountnumber)
q List all the customer’s who have both a loan & an account.
Relational Algebra=
customername(Borrower) customername (depositor)
SQL=
select customername from Borrower intersect
select customername from Depositor
RENAME operation :
RENAME operation is used rename attributes. It is
denoted as ρ(row)
Example : Employee (name, eid)
Change attributes name to employee name
SQL=
Select* from students INNER JOIN
courses on students.course= courses.course;
qNatural join :-
A natural join offers a further specialization of equi-
joins. The join predicates arise implicitly by comparing
all columns in both tables that have the same column-
name in the join tables. The resulting tables one
column for each pair of equally named columns.
Relation algebra=
Students <course=course#>courses
Syntax;
R <r-primary key =s. foreign-key>s
Example
Student <student. Course= courses. course#> courses
Conceptual internal
mapping
Internal level Internal schema
Store database
-Internal level :
Internal level has an internal schema which describe
the physical storage structure of the database. The
internal schema uses a physical data model and
describes the complete details of data storage and
access path for the database.
- Conceptual level :
Conceptual level has a conceptual schema, which
describe the structure of the whole database for a
community of users. The conceptual schema hides the
details of physical storage structure and concentrates
on describing entities, data types, relationship users
operation & constraints.
- External level :-
External level includes a number of external schema
or user view. Each external schema describes a part of
the database that a particular user group is interested
in and hides that rest of the database from that user
group.
# Instance:-
Actual data in the database may change quite
frequently. For example, the database change
every time we add a student or enter the new
grade .The data in the database at a particular
moment in time is called a database State or snap
shot . It is also called the current set of
occurrences or instances in the database.
View:- View is a single table that is described
from other tables. These other tables can be
base tables or previously defined views. A view
doesn’t necessarlly exist in physical form, it is
considered a virtual table.
Advantages of views:-
– View can represent a subset of the data contained in
a table.
– Views can join multiple table into a single virtual
table.
– View can hide the complexity of data.
– View take very little space to store.
SQL CREATE VIEW Syntax
CREATE VIEW view_name AS SELECT
column1, column2..... FROM table_name
WHERE [condition];
Unit -4
Relation laguages
SQL(Structure Query Language)
Definition:
SQL (Structured Query Language is a special-
purpose programming language designed for
managing data held in a relational database
management system (RDBMS).
Originally based upon relational algebra and
tuple relational calculus, SQL consists of a data
definition language and a data manipulation
language. The scope of SQL includes data insert,
query, update and delete, schema creation and
modification, and data access control.
History:
SQL was initially developed at IBM by Donald D.
Chamberlin and Raymond F. Boyce in the early 1970s.
This version, initially called SEQUEL (Structured English
Query Language), was designed to manipulate and
retrieve data stored in IBM's original quasi-relational
database management system, System R, which a
group at IBM San Jose Research Laboratory had
developed during the 1970s.The acronym SEQUEL was
later changed to SQL.
In the late 1970s, Relational Software, Inc. (now Oracle
Corporation) saw the potential of the concepts
described by Codd, Chamberlin, and Boyce and
developed their own SQL-based RDBMS with
aspirations of selling it to the U.S. Navy, Central
Intelligence Agency, and other U.S. government
agencies.
In June 1979, Relational Software, Inc.
introduced the first commercially available
implementation of SQL, Oracle V2 (Version2)
for VAX computers.
After testing SQL at customer test sites to
determine the usefulness and practicality of
the system, IBM began developing commercial
products based on their System R prototype
including System/38, SQL/DS, and DB2, which
were commercially available in 1979, 1981,
and 1983, respectively.
Query:
• In computers, what a user of a search engine
or database enters is sometimes called the
query. To query (verb) means to submit a
query (noun).
• A database query can be either a select query
or an action query. A select query is simply a
data retrieval query. An action query can ask
for additional operations on the data, such as
insertion, updating, or deletion.
Sub queries :
A sub query is a form of an SQL statement that
appears in inside another SQL statement it is
also termed nested query. Subqueries can be
used with the SELECT, INSERT, UPDATE, and
DELETE statements along with the operators
like =, <, >, >=, <=, IN, BETWEEN etc.
It can be used by the following commands.
- To insert records in a targets in the table created.
- To update records in a target table .
- To create view
Data types(Domain) in SQL :
Is an attribute that specifies the types of data that the
object can hold integer data, character data, date and
time data and so on.
Some of data types are given below.
Char (size)
This data types is used to store character string
values of fixed length. The size in brackets determine
the number of characters the cell can hold.
Varchar(size)/ Varchar2(size) :
This data types is used in store variable length
alphanumeric data.
Number :
The number is used to store number (fixed or
floating point) in database.
Date :
This data types is used to represent date
& time. The standard format is DD-MM-YY as
21-jun-2012.
Long :
This data type is used to store variable
length character string containing upto 2
GB.
Boolean :-
This data type has values of True and
False.
o Date/Time Use for dates and times
o Text: Use for text or combinations of text and
numbers. 255 characters maximum.
o Memo: Memo is used for larger amounts of text.
Stores up to 65,536 characters.
o Yes/No A logical field can be displayed as Yes/No,
True/False, or On/Off.
o AutoNumber: AutoNumber fields automatically
give each record its own number, usually starting
at 1.
o Currency: Use for currency. Holds up to 15 digits
of whole dollars, plus 4 decimal places.
• Binary Objects: A relatively new domain is to
separate category for objects or binary large
objects (BLOB). It enables us to store any type
of object created by the computer. A good e.g.
is to use a BLOB to hold files from other
software packages. An engineering database
might hold drawings and specifications for
various components. The advantage is that all
of the data is stored together making it easier
for users to find the information they need
and simplifying backups.
• Computed values: Some business attributes
can be computed. For instance the total value
of a sale can be calculated as the sum of the
individual sale prices plus the sales tax, or an
employee’s age can be computed as the
difference between today’s date and Date of
Birth. At the design stage, you should indicate
which data attributes could be computed. The
UML notation is to precede the name with a
slash (/) sign and then describe the
computation in a note.
• Events : Events are another important components of
modern database systems that we need to record.
Three basic types of events occur in a database
environment.
· Business events that trigger some functions, such
as a sale triggering a reduction in inventory
· Data changes that signal some alert, such as an
inventory that drops below a present level, which
triggers a new purchase order, and
· User interface events that trigger some
action, such as a user clicking on an icon to
send a purchase order to a supplier.
Events are action that is dependent on time.
DDL : (Data definition language )
DDL is a syntax similar to a computer programming
language for defining data structures, specially
database schemas.
Many data description, language SQL uses a
collection of imperative verb whose effect is to
modify the schema of database by adding changing
and deleting definitions of table or other objects .
Create statements :
To make a new database table, index or view etc.
Syntax.
CREATE TABLE[table name]
(columnname1 data types (size), column name2 data types
(size)………));
Example :-
Create employee table having same attributes.
BETWEEN Operator:
Allows the selection of rows that contains values
within a specified lower and upper limit.
Example :
✓ Retrieve all information from the table product-
master where the values contain within the field
profit-percent is betn 10 & 20 both inclusive.
✓ Aggregate functions:
SQL aggregate functions return a single value,
calculate from the values in column.
i) Avg : returns the average value.
eg.
select avg(sell-price)“Average” from
product_master;
ii) MIN :
Returns the smallest value.
Eg.
select MIN(bal-due) “minimum balance”
from client_master;
v) Max():
Returns the largest value.
Exmaple :
vii) SQRT :-
Returns square root of ‘n’ .
example :
select SQRT (25) “Square Root” from dual;
Group By clause :
Group by clause is another section of the select
statement. To group rows based on distinct
values that exits for specified column i.e. it
creates a data set, containing several set of
records grouped together based on a condition.
Table : sales
Detail ord no. Product No. Qty ordered Qty Dispatched
019001 P0001 10 10
019001 P0004 3 3
019001 P0006 1 7
019002 P0002 4 4
019002 P0005 10 10
019003 P0003 2 2
019004 P0001 6 6
019005 P0006 4 4
019005 P0004 1 1
019006 P0006 8 8
Example :
Retrieve the product and the total quantity
ordered for each product from the sales tables.
For eg:
If there are 3 attributes involved in a relation,A,B, and C..
Then for every value of A we will have respective values for B
and C. Then it is called multivalue dependency.
MVD or Multivalued Dependency is a dependency where one
attribute value is potentially a "multivalued fact" about
another and the attributes must be independent of each other.
Data constraints/Data rules and integrity :-
Rules which are enforced on data being
entered and prevents the user from
entering invalid data into tables are called
constraints. Thus constraints control data
being entered in tables for permanent
storage.
Data constraints to be attached to table
column via SQL syntax that will check data
for integrity.
Types of data constraints :
i)I/O Constraints :
This data constraint determine the speed at
which data can be inserted or extracted
from a table. I/O constraints divided into
two parts.
a. Primary key constraints
• that the data entered in the table column
is unique.
• That none of the cells belonging to the
table column left empty.
b. Foreign key constraints :
This constraints establishes a relationship
between records. This relationship ensures :
• Records can not be inserted into a detail table if
corresponding records in the master table do not
exist.
ii) Business Rule constraints :
DBMS allows the application of business rules to
table columns. Business manager determine,
business rules. These rules are applied to data
prior the data being inserted into table columns
eg,
The rule that no employee in the company shall
get salary less than Rs.1000/- is a business rule.
Trigger :
A database trigger is procedural code that is
automatically executed in response to certain
events on a particular table or view in a database.
In addition to trigger that fire when data is
modified & when user logon or logoff events occur.
There are four type of trigger:
→ Row level Trigger :This gets executed before or
after any column value of a row changes
→Column level Trigger :This gets executed before or
after the specified column changes.
→ For each row types : This trigger gets executed
once for each row of the result set cause by
insert/update/delete.
→For each statement : This trigger executed only
once for the entire result set, but fires each time
the statement is executed.
Unit- 6
Security :
- The security of a database can be thought
of as a barrier which prevents unauthorized
access of data.
- Database security concerns the use of a
broad range of information security
controls to protect database (potentially
including the data, the database application
or stored functions, the data base systems,
the database severs and the associated
networks links) against compromises of
their confidentily, integrity and availability.
- It involves various types or categories of control,
such as technical, procedural administrative and
physical.
Need of security :
- Unauthorized or unintended activity or misuse by
authorized database users, database
administrator or network system managers, or by
unauthorized user or hackers.
- Mal ware infections causing incidents such as
unauthorized access, leakage or disclosure of
personal or proprietary data, deletion or damage
to the data or program.
- Overloads, performance constraints and capacity
issues resulting in the inability of authorized
users to use databases as intended.
- Physical damage to database serves caused
by computer room fires or floods,
overheating, lightning, accidental liquid
spills, static discharge, electronic
breakdown/ equipment failures.
# Access Control :
- Access control mechanisms enforce rules
about who can perform what operation or
who can access which data.
- Thus any access control mechanism must
concern itself which three basic
components, namely.
i) Identification and authentication of Accessor :
- The process of identification may involves several
parameters such as personal identification of
accessor, location of accessor, time and day of
access, frequency of access etc.
- Personal identification may be performs with the
help of passwords, voice prints, finger prints
signatures etc.
- The process of authentication requires supplying
information known only to the person the
accessor has claimed to be.
- This may be done by quoting a password or by
answering some question from system.
- The location of the accessor or time and day of
access are also useful in detecting unauthorized
access.
ii) Object to be locked :-
a) Data object :
The data objects to be locked may be files or
some records of a file. Sometimes if may be
necessary to lock and privacy keys are used to
control access to a particular record type.
b) View :
The another levels of security provided by
DBMS is defining views or the external model of
the schema. The owner of a database may grant
views which may consist of the entire data base
or a certain portion of the database.
c) Type of Access :-
Once an object is created, the own may grant
other genuine accessors any of the following
access right the object. Read, Run, modify, delete
insert, create , Destroy.
iii) Crypto System:
A cryptosystem is the combination of three
elements an encryption engine keying
information, and operational procedures for their
secure use.
In other to cryptographically secure high-value
data on a hard disk (or on back-up media), it is
necessary to employ a high-grade cryptosystem:
one which even an attacker processing both a
copy of your encryption engine and knowledge of
your operating procedures cannot break without
your keying information.
Encryption and Decryption :
- Encryption is a method of modifying the
original information according to some
code so that it can be read only if the user
known the decryption key.
- - Encryption should be used when
transmitting information from one
computer to another particularly when
using the internet.
- Sensitive information store within a
database also can be encrypted.
- Decryption is the reserve operation of
encryption.
- The process of decoding data that has been
encrypted into a secret format decryption
requires a secret key or password.
(Advanced encryption Standard)
Fig : single-key encryption
Plain text message
Encrypted text
AES
Key : 9837362
Data files
Basic Steps in Query Processing