Unit1 DBMS
Unit1 DBMS
Unit1 DBMS
Sub Code:18BIT52C
Prepared by Dr.P.Radha
SYLLABUS
UNIT I: Database Concepts: A Relational approach: Database–Relationships–DBMS–
Relational Data Model–Integrity Rules–Theoretical Relational Languages. Database Design:
Data Modeling and Normalization: Data Modeling–Dependency–Database Design – Normal
forms– Dependency Diagrams -Renormalizations – Another Example of Normalization.
UNIT II: Oracle9i: Overview: Personal Databases–Client/ServerDatabases–Oracle9i an
introduction– SQL*Plus Environment–SQL–Logging into SQL*Plus–SQL*Plus Commands–
Errors &Help–Alternate Text Editors-SQL*Plus Worksheet – iSQL*Plus .Oracle Tables:
DDL: Naming Rules and conventions– Data Types–Constraints–Creating Oracle Table–
Displaying Table Information–Altering an Existing Table–Dropping, Renaming, Truncating
Table–Table Types–Spooling–Error codes.
UNIT III: Working with Tables: Data Management and Retrieval: DML – Adding a new
Row/Record – Customized Prompts – Updating and Deleting Existing Rows/Records–
Retrieving Data from A Table– Arithmetic Operations– Restricting Data with WHERE
clause– Sorting– Revisiting Substitution Variables–DEFINE command–CASE structure.
Functions and Grouping: Built-in functions – Grouping Data Multiple Tables: Joins and Set
operations: Join–Set Operators.
UNIT IV: PL/SQL: A Programming Language: History–Fundamentals–Block Structure–
Comments – Data Types–Other Data Types–Variable Declaration–Anchored Declaration-
Assignment operation – Bind Variables–Substitution Variables–Printing–Arithmetic
Operators. Control Structures and Embedded SQL: Control Structures–Nested Blocks–SQL in
PL/SQL–Data Manipulation –Transaction Control statements. PL/SQL Cursors and
Exceptions: Cursors – Implicit & Explicit Cursors and Attributes–Cursor FOR loops–
SELECT…FOR UPDATE – WHERE CURRENT OF clause– Cursor with Parameters–
Cursor Variables– Exceptions– Types of Exceptions.
UNIT V: PL/SQL:PL/SQL Composite Data Types: Records–Tables– arrays. Named Blocks:
Procedures–Functions–Packages–Triggers – Data Dictionary Views.
UNIT I
Database Concepts: A Relational approach: Database–
Relationships–DBMS–Relational Data Model–
Integrity Rules–Theoretical Relational Languages.
Database Design: Data Modeling and Normalization:
Data Modeling–Dependency–Database Design –
Normal forms– Dependency Diagrams -
Renormalizations – Another Example of
Normalization.
Text Book: “DATABASE SYSTEMS USING ORACLE”-NILESH SHAH,2nd Edition, PHI
Prepared by Dr.P.Radha
Database Concepts: A Relational
Approach
• Database
• Relationships
• DBMS
• Relational Data Model
• Integrity Rules
• Theoretical Relational Languages
DATABASE AN INTRODUCTION
OS Software
Hardware
Cont..
• The information is produced when a user uses
the applications to transform data managed by
the DBMS.
• The database system is utilized as a decision-
making system and is also referred to as an
information system (IS).
Cont..
• A DBMS based on the relational model is also known
as a Relational Database Management System
(RDBMS).
• An RDBMS not only manages data but is also
responsible for other important functions:
• It manages the data and relationships stored in the
database. It creates a Data Dictionary as a user creates a
database.
• The Data Dictionary is a system structure that stores
Metadata (data about data).
• The Metadata include table names, attribute names,
data types, physical space, relationships, and so on
Cont…
An RDBMS not only manages data but is also
responsible for other important functions:
• It manages the data and relationships stored in the
database.
• It creates a Data Dictionary as a user creates a
database.
• The Data Dictionary is a system structure that
stores Metadata (data about data).
• The Metadata include table names, attribute
names, data types, physical space, relationships,
and so on
Cont..
• It manages all day-to-day transactions
• It performs bookkeeping duties, so the user has data
independence at the application level. The applications
do not have information about data characteristics
• It transforms logical data requests to match physical
data structures.
• When a user requests data, the RDBMS searches
through the Data Dictionary, filters out unnecessary
data, and displays the results in a readable and
understandable form.
Cont..
• It allows users to specify validation rules. For
example, if only M and F are possible values for
the attribute gender, users can set validation rules
to keep incorrect values from being accepted
• It secures access through passwords, encryption,
and restricted user rights.
• It provides backup and recovery procedures for
physical security of data.
• It allows users to share data with data-locking
capabilities.
Cont..
• It provides import and export utilities to use data
created in other database or spreadsheet software
or to use data in other software.
• It enables users to join tables to view information
stored in different tables within the database. The
user is able to design a database with less
redundancy, which means fewer data-entry errors,
fewer data corrections, better data integrity, and a
more efficient database
RELATIONAL DATABASE MODEL
• Codd proposed these languages to embed them in other host languages for
more processing capability and more sophisticated application
development.
• The join is based on common set of values, which does not have to have
the same name in both tables but does have to have the same domain in
both tables. When a join is based on equality of value, it is known as a
natural join.
• And also about other types of joins, such as outer join, non equijoin, and
,self-join, that are based on the operators other than the equality operator.
Cont..
Division
• The division operation is the most difficult
operation to comprehend.
• It is not as simple as division in mathematics.
In relational algebra, it identifies rows in one
table that have a certain relationship to all rows
in another table. Let us consider the following
two tables.
Cont..
Database Design: Data Modeling and
Normalization
• Data Modeling
• Dependency
• Database Design
• Normal forms
• Dependency Diagrams
• Renormalizations
• Another Example of Normalization
DATA MODELING
• A model is a simplified version of real-life,
complex objects.
• Databases are complex, and data modeling is a
tool to represent the various components and
their relation-ships
• The entity-relationship (E-R) model is a very
popular modeling tool among many such tools
available today. Many tools are available for
data modeling with E-R
Cont…
• All tools have some variations in
representation of components.
• The E- R model provides:
An excellent communication tool.
A simple graphical representation of data.
Cont…
• The E-R model uses E-R diagrams (ERD) for
graphical representation of the database
components.
• An entity (or an entity set) is represented by a
rectangle.
• The name of the entity (set) is written within the
rectangle.
• Some tools prefer to use uppercase letters only for
entities. The name of an entity set is a singular
noun. For example, EMPLOYEE, CUSTOMER,
and DEPARTMENT are singular entity set names.
Cont…
• A line represents relationship between the two
entities.
• The name of the relationship is an active verb
in lowercase letters.
• For example, works; manages, and employs
are active verbs. Passive verbs can be used, but
active verbs are preferable
Cont…
Cont…
Cont…
• The types of relationships (1:1, 1:M, and M:N)
between entities are called connectivity or
multiplicity.
• The connectivity is shown with vertical or angled
lines next to each entity, For example, an
EMPLOYEE supervises a DEPARTMENT, and a
DEPARTMENT has one EMPLOYEE supervisor.
• A DIVISION contains many FACULTY
members, but a FACULTY works for one
DIVISION. An INVOICE contains many ITEMs,
and an ITEM can be in more than one INVOICE.
Cont…
• Let us put everything together and represent
these scenarios with the E-R dia- gram that
shows entities, relationships, and connectivity
• The relationship between two entities can be
given using the lower and upper limits. This
information is called the cardinality.
• The cardinality is written next to each entity
in the form (n, m), where n is the minimum
number and m is the maximum number
Cont…
• For example, (1,1) next to EMPLOYEE means
that an employee can supervise a minimum of one
and a maximum of one department.
• Similarly, (1,1) next to DEPARTMENT says that
one and only one employee supervises the
department.
• The value (1,N) means a minimum of one and a
maximum equal to any number. Some modern
tools do not show cardinality in an E-R diagram
Cont…
Cont…
• In reality, corporations set rules for the minimum
and maximum values for cardinality.
• A corporation may decide that a department must
have a minimum of 10 employees and a
maximum of 25 employees, which results in
cardinality of (10,25).
• A college decides that a computer-science course
section must have at minimum 5 students to
recover the cost incurred and at maximum 35
students, because the computer lab contains only
35 terminals
Cont…
• An employee can be part of zero or more than
one department, and an item may not be in any
invoice! These types of decisions are known as
business rules.
• The above E-R diagram with added cardinality. In
real life, it is possible to have an entity that is not
related to another entity at all times. The
relationship becomes optional in such a case. In
the example of a video rental store. a customer
can rent video movies
Cont…
• In this case there are times when the customer
has not rented any movie, and there are times
when the customer has rented one or more
movies.
• Similarly, there can be a movie in the database
that is or is not rented at a particular time.
Cont…
• These are called optional relationships and are
shown with a small circle next to the optional
entity.
• The optional relationship can occur in 1:1,
1:M, or M:N relationships, and it can occur on
one or both sides of the relationship
Cont…
• In relational databases, many-to-many (M:N)
relationships are allowed, but they are not easy to
implement.
• For example, an invoice has many items. and an item
can be in many invoices. Refer to the INVOICE and
ITEM relationship .
• At this point, you will he introduced to the relational
schema, a graphical representation of tables, their
column names, key components, and relations between
the primary key in one table and the foreign key in
another. You will also see the decomposition of an M:N
relationship into two 1:M relationships
Cont…
• The decomposition from M:N to 1:M involves a third
entity, known as a composite entity or an associative
entity.
• The composite entity is created with the primary key
from both tables with M:N relationships.
• The new entity has a composite key, which is a
combination of primary keys from the original two
entities. In the E-R diagram. a composite entity is
drawn as a diamond within a rectangle.
• The composite entity has a composite primary key with
two columns, each of them being foreign keys
referencing the other two entities in the database.
Cont..
• For example, the foreign key INVOICENO in the
INVITEM table references the INVOICENO column in the
INVOICE table, and the foreign key ITEMNO in the
INVITEM table references the ITEMNO column in the
ITEM table.
• In a database, there are entities that cannot exist by
themselves.
• Such entities are known as weak entities. you will be
introduced to two different sample databases.
• In the employee database of that chapter, there is an entity
called EMPLOYEE with employees' demographic
information and another entity called DEPENDENT with
information about each employee's dependents.
Cont…
• The DEPENDENT entity cannot exist by
itself. There are no dependents for an
employee who does not exist.
• In other words, you need the existence of an
employee for his or her dependent to exist in
the database. The weak entities are shown by
double lined rectangles
Cont…
Weak Entity
• Some of the other elements considered in the
database design are:
Simple attributes—attributes that cannot be
subdivided; for example, last name, city, or gender.
Composite attributes—attributes that can be
subdivided, into atomic form; for example, a full name
can be subdivided into the last name, first name, and
middle initial.
Cont..
• Single-valued attributes—attributes with a single
value; for example, Employee ID, Social Security
number, or date of birth.
• Multivalued attributes—attributes with multiple
values; for example, degree codes or course
registration. The multivalued attributes have to be
given special consideration.
• They can be entered into one attribute with a
value separator mark, or they can be entered in
separate attributes with names like Course l,
Course2, Course3, and so on. Alternatively, a
separate, composite entity can be created
DEPENDENCY
• Every table in the database should have a primary key,
which uniquely identifies an entity.
• For example, PartNo is a primary key in the PARTS table,
and DeptNo is a primary key in the DEPARTMENT table.
• In Oracle, if you create a table and do not define its primary
key.
• Oracle does not consider it to be an error. You should
define a primary key for all tables for integrity of data.
Each table has other columns that do not make up the
primary key for the table.
• Such columns are called the non key columns. The non key
columns are functionally dependent on the primary key
column.
Cont…
• For example, Part Desc and Cost in the PARTS table are dependent on the
primary key Par tNo, and DeptName is dependent on the primary key
DeptNo in the DEPARTMENT table
• Now, let us take a scenario as shown below. The INVOICE table in does
not have any single column that can uniquely identify an entity.
• The first choice would be InvNo. It is not a unique value in the table,
however, because an invoice may contain more than one item and there
may be more than one entry for an invoice.
• CustNo cannot be the primary key, because there can be many invoices for
a customer and CustNo does not identify an invoice. ItemNo cannot be the
primary key either, because an item may appear in more than one invoice
and ItemNo does not describe an invoice.
• The table has a composite primary key, which consists of InvNo and
ItemNo. InvNo and ItemNo together make up unique values for each row.
All other columns that do not constitute the primary key are nonkey
columns, and they are dependent on the primary key.
INVOICE
• They are not dependent on the InvNo column. Similarly, the non key