introduction to rdbms introduction to rdbms. rdbms relational database management system. data is...
TRANSCRIPT
Introduction to RDBMS
RDBMSRelational database management system.Data is stored in the form of tables and there is a
relationship between these tables.
DATA PROCESSINGSequence of operations on data to convert it
into useful information.Different operations and methods are applied
on the data.OPERATIONS- Arithmetic and logical operations. To send and receive data from one location to
other. Classification of data. Arranging data into a specific order etc.
METHODS OF DATA PROCESSINGManual data processing.Mechanical data processing.Electronic data processing.
DATA MODELS Data Model can be defined as an integrated
collection of concepts for describing and manipulating data, relationships between data, and constraints on the data in an organization.
It is used for representing entities of interest and their relationships in database.
TYPES OF DATA MODELSRecord-based data modelObject- based data modelPhysical data model
RECORD BASED DATA MODELSRecord based data models specify the overall
logical structure of the database and provides a higher-level description of the implementation.
Record based models are so named because the database is structured in fixed format records of several types.
The three most widely accepted record based data models are:
• Hierarchical Model
• Network Model
• Relational Model
OBJECT BASED MODELSObject–based data models are used to describe data
and its relationships. It uses concepts such as entities, attributes and
relationships.Following are the common types of object-based
data models:
• Entity-Relationship
• Object Oriented
• Semantic
• Functional
PHYSICAL DATA MODELSPhysical data models describe how data is stored
in the computer, representing information such as record structures, record ordering, and access paths.
Two types of physical data models are:
• Unifying model
• Frame memory model
HIERARCHICAL DATA MODEL
A hierarchical database model is a data model in which the data is organized into a tree-like structure. The data is stored as records which are connected to one another through links.
E.g.University
Department
Faculty
NETWORK DATA MODELThis model is same as hierarchical model, except
that a record can have multiple parents. Network model has three basic components-
record type , data items and links.
RELATIONAL DATA MODELRelational model stores data in the form of
tables. The relational model consists of three major components:
The set of relations and set of domains that defines the way data can be represented (data structure).
Integrity rules that define the procedure to protect the data (data integrity).
The operations that can be performed on data (data manipulation).
DATABASE DESIGN TECHNIQUES
Top down Approach
– E R Modeling Bottom Up approach
– Normalization
ER MODELLINGThe ER model is a conceptual data model
that views the real world as entities and relationships.
A basic component of the model is the Entity-Relationship diagram, which is used to visually represent data objects.
Entity relationship model defines the conceptual view of database.
BASIC CONCEPTS IN ER MODEL An entity is an object that exists and is distinguishable from
other objects.◦ Example: specific person, company, event, plant
An entity set is a set of entities of the same type that share the same properties.◦ Example: set of all persons, companies, trees, holidays
Entities have attributes- simple attributes, composite attributes, derived attributes, single-valued attributes etc.◦ Example: people have names and addresses
A relationship A Relationship represents an association between two or more entities. Relationships are classified in terms of degree, connectivity, cardinality, and existence.
DEGREE OF RELATIONSHIP- The number of participating entities in an relationship defines the degree of the relationship.
Unary = degree 1
Binary = degree 2
Ternary = degree 3 employee manager-of employee is unary employee works-for department is binary customer purchase item, shop keeper is a ternary
relationship
MAPPING CARDINALITIES:
Cardinality defines the number of entities in one entity set which can be associated to the number of entities of other set via relationship set..
One-to-one: one entity from entity set A can be associated with at most one entity of entity set B and vice versa
One-to-many: One entity from entity set A can be associated with more than one entities of entity set B but from entity set B one entity can be associated with at most one entity.
Many-to-one: More than one entities from entity set A can be associated with at most one entity of entity set B but one entity from entity set B can be associated with more than one entity from entity set A.
Many-to-many: one entity from A can be associated with more than one entity from B and vice versa.
NOTATIONS IN ER MODEL
EXTENDED ER FEATURESSpecialization: Top-down design process.
Specialization is the process of taking subsets of a higher-level entity set to form lower level entity sets. It is a process of defining a set of subclasses of an entity type, which is called as superclass of the specialization.
For example, specialization of the Employee entity type may yield the set of subclasses namely Salaried_Employee and Hourly_Employee on the method of pay
Generalization: A bottom-up design process
A generalization hierarchy is a form of abstraction that specifies that two or more entities that share common attributes can be generalized into a higher-level entity type called a super type or generic entity. The lower level of entities becomes the subtype, or categories, to the super type. Subtypes are dependent entities. Generalization is denoted through a triangle component labeled ‘IS A”.
Aggregation
One limitation of the E-R model is that it cannot express relationships among relationships.
The best way to model a situation like this is by the use of aggregation.
NORMALIZATIONNormalization is a process of decomposing a set of
relations with anomalies to produce smaller and well structured relations that contain minimum or no redundancy.
It is a formal process of deciding which attributes should be grouped together in a relation.
The process of normalization can be defined as the procedure of successive reduction of a given collection of relational schemas based on their FD’s and primary keys to achieve some desirable form of minimized redundancy.
NORMAL FORMSFirst normal form (1NF)Second normal form (2NF)Third normal form (3NF)Boyce/ Codd normal form (BCNF)Fourth normal form (4NF)Fifth normal form (5NF)
LOGICAL DATABASE DESIGN The logical design is more conceptual and abstract than the
physical design. In the logical design, you look at the logical relationships
among the objects. In the physical design, you look at the most effective way of storing and retrieving the objects.
The process of logical design involves arranging data into a series of logical relationships called entities and attributes. An entity represents a chunk of information. In relational databases, an entity often maps to a table. An attribute is a component of an entity and helps define the uniqueness of the entity. In relational databases, an attribute maps to a column.
You can create the logical design using a pen and paper, or you can use a design tool such as Oracle Warehouse Builder or Oracle Designer.
SQL (Structured Query Language)SQL is a relational the query language.
It is the standard command set used to communicate with the relational database management system (RDBMS).
It is a non-procedural language.SQL is both data definition language and
data manipulation language.
COMPONENTS OF SQLData structure.Data type.SQL operators.Data definition language (DDL)Data query language (DQL)Data manipulation language (DML)Data control language (DCL)Data administration statements (DAS)Transaction control statements (TCS)
ADVANTAGES AND DISADVANTAGESAdvantages: very flexible , free-format syntax. Supported by every product. It can express arithmetic operations as well as
operations to aggregate data and sort data for output.
Disadvantages: It is not a general-purpose programming language
and thus the development of an application requires the use of a SQL with a programming language.
DDL(Data Definition Language)DDL is a special language used to specify a
database conceptual schema using set of definitions. It supports the definitions or declaration of objects.
Create Alter Drop Truncate
DML(Data Manipulation Language)DML is a mechanism that provides a set of
operations to support the basic data manipulation operations on the data.
It is used to retrieve data stored in a database, express database queries and updates . It helps in communicating with DBMS.
InsertUpdateDeleteSelect
DCL (Data Control Language)DCL statements are used to control access to
data stored in a database.Commands of DCL are:GrantRevokeCommit Rollback
SQL JOINSSQL join is used for combining column from
two or more tables by using values common to both tables.
Join keyword is used in SQL queries for joining tables.
Minimum required condition is ,(n-1).A table can also join to itself known as, Self Join
TYPES OF JOINSCartesian ProductInner joinEqui joinOuter join
– Left-outer join
– Right-outer joinSelf join
Cartesian Product: Returns All rows from first table, Each row from the first table is combined with all rows from the second table.
Inner join : is the Cartesian product that satisfies the join condition in the WHERE clause.
Equi join : In this join , where clause is based on the equality condition “=“. Hence it is called equi join.
Outer Join: Retrieve all rows that match the WHERE clause and also those that have a NULL value in the column used for join.
Left outer joins include all records from the first (left) of two tables,
A = B (+)Right outer joins include all records from the
second (right) of two tables,
A (+) = B
SUB QUERIESQueries inside the main query.Sub queries are used to structure the queries.In many cases, a sub query can be used instead
of a JOIN (and vice versa)e.g Select cust_ID, Loan_no
From Customer_Loan
Where amount_in_dollars >
(Select amount_in_dollars
From Customer_Loan
Where Cust_ID = 104);
VIEWSA view is a kind of “virtual table”.Views are tables whose contents are taken or
derived from other tables.To the user, the view appears like a table with
columns and rows. But in reality, the view doesn’t exists in the database as a stored set of values
View is like a window through which we see a limited region of the actual table
The table from where the actual data is obtained is called the source table
We can use views in select statements like.
Select * from view_employees where age > 23;
Create a view
e.g.CREATE VIEW ViewCustomerDetails
AS SELECT *FROM Customer_Details;
TYPES OF VIEWSHorizontal views- Horizontal view restricts a user’s
access to only selected rows of a table.Vertical views - A view which selects only few
columns of a table, Vertical view restricts a user’s access to only certain columns of a table
Row/column subset views –
e.gCREATE VIEW View_Cust_VertHor
AS SELECT Cust_Id,Account_No,Account_Type
FROM Customer_Details
WHERE CUST_ID IN (101,102,103);
Grouped views-The query contains a group by clause
e.g CREATE VIEW View_GroupBY(Dept,NoofEmp)
AS SELECT Department, count(Employee_ID)
FROM Employee_Manager
GROUP BY Department; Joined views- Created by specifying a two-table or
three-table query in the view creation command
e.g. Create view View_Cust_Join as
Select a.Cust_Id,b.Cust_First_Name,b.Cust_Last_Name,
Amount_in_dollars
from Customer_loan a, customer_details b
where a.cust_id = b.cust_id;
DATABASE DESIGN ISSUESPoor or missing documentation for
database(s) in productionLittle or no normalizationNot treating the data model like a living,
breathing organismImproper storage of reference dataNot using foreign keys or check
constraintsNot using domains and naming
standardsNot choosing primary keys properly
ANY QUERIES???