0% found this document useful (0 votes)
93 views45 pages

2 RDBMS

The document defines key concepts in database modeling including hierarchical, network, and relational models. It then describes components of the relational database model including entities, attributes, relations, tuples, domains, and keys. It discusses relational data structure including the concepts of relations, attributes, tuples, domains, and keys. It also covers data integrity and data manipulation in relational database management systems.

Uploaded by

anisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views45 pages

2 RDBMS

The document defines key concepts in database modeling including hierarchical, network, and relational models. It then describes components of the relational database model including entities, attributes, relations, tuples, domains, and keys. It discusses relational data structure including the concepts of relations, attributes, tuples, domains, and keys. It also covers data integrity and data manipulation in relational database management systems.

Uploaded by

anisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 45

DATABASE MODEL

• A Database model defines the logical design of


data. The model describes the relationships
between different parts of the data. Historically, in
database design, three models are commonly used.
They are,
• Hierarchical Model
• Network Model
• Relational Model
 HIERARCHICAL MODEL
• In this model each entity has only one parent but
can have several children . At the top of hierarchy
there is only one entity which is called Root.
NETWORK MODEL
• In the network model, entities are organized in a
graph , in which some entities can be accessed
through several path.
RELATIONAL MODEL
• In this model, data is organized in two-dimensional
tables called relations. The tables or relation are
related to each other.
RDBMS
INTRODUCTION

• The Relational Database Management Systems are


based on relational Model.
• The Relational Model , in turn ,is a way of looking at
data.
• It is prescription for how to represent and
manipulate data.
RDBMS COMPONENTS

• More precisely the relational model is concerned


with three components:
• Data Structure
• Data Integrity
• Data Manipulation
I- RELATIONAL DATA
STRUCTURE
RELATIONAL DATA STRUCTURE

1.Entity: An entity can be a real-world object, either


animate or inanimate, that can be easily
identifiable. For example, in a school database,
students, teachers, classes, and courses offered can
be considered as entities.
2.Relation: A Relation is a table with rows and
columns . All data and relationships are
represented in 2D table called relation . RDBMS
requires only the user percieve data as table
• 3.Attribute :An attribute is a named column of a
relation.
• Attributes can appear in any order and the relation
will still be the same relation , and therefore convey
same meaning.
• 4.Domain:A domain is the set of allowed values for
one or more attributes.
• A domain is the set of all possible values that an
attribute may validly contain.
• Each attribute in the model should be assigned
domain information that includes:
• Data Type :Basic data type as integer,decimal or character. Most
databases support variants of these.
• Length: this is the number of digits or characters in the values.
• Date format : the format of date value as dd/mm/yy or mm/dd/yy
• Range : the range specifies the lower and upper boundaries of
the values of attributes may legally have.
• Constraints: are special restrictions on allowed values
• Null Support: Indicates whether the attribute can have null or
unknown value.
• Default Value: the value an attribute will have if a value is not
entered.
• Tuple: A tuple is a row of a relation.
• Extension of a Relation: It is the set of tuples
appearing in that relation at any given instant of
time . The extension thus varies with time.
• Intension of a Relation : It is the permanent part of
the relation and independent of time , it correspond
to what is specified in the relational schema.
• Degree : the degree of relation is the number of
attributes it contains.
• Cardinality : The cardinality of a relation is the
number of tuple it contains.
II-DATA INTEGRITY
• data integrity” refers to the accuracy
and consistency of datastored in
a database, data warehouse, data mart or other
construct. The term –Data Integrity - can be used
to describe a state, a process or a function – and is
often used as a proxy for “data quality”.
• In order to discuss data integrity ,we have to
understand keys
• There should not be any duplicate tuple within a
relation,therefore we should identify one or more
attributes(called relational keys) that uniquely
identify each tuple in a relation.
III-DATA MANIPULATION
Types of DBMS languages:

• Data Definition Language (DDL): DDL is used for


specifying the database schema. Let’s take SQL for
instance to categorize the statements that comes
under DDL.
• To create the database instance – CREATE
• To alter the structure of database – ALTER
• To drop database instances – DROP
• To delete tables in a database instance – TRUNCATE
• To rename database instances – RENAME
• All these commands specify or update the database
schema that’s why they come under Data Definition
language.
• Data Manipulation Language (DML): DML is used
for accessing and manipulating data in a database.
• To read records from table(s) – SELECT
• To insert record(s) into the table(s) – INSERT
• Update the data in table(s) – UPDATE
• Delete all the records from the table – DELETE
•  
• Data Control language (DCL): DCL is used for
granting and revoking user access on a database –
• To grant access to user – GRANT
• To revoke access from user – REVOKE
• In practical data definition language, data
manipulation language and data control languages
are not separate language; rather they are the parts
of a single database language such as SQL.
Transaction Control Language:

• It manage the changes made by DML .


• COMMIT-make transaction changes permanent
• ROLLBACK-undo changes made by transaction
either since it started or since save point
• SAVEPOINT-set point to which transaction can be
rolled back
• SET TRANSACTION-establish properties for
transaction
KEYS
Keys
• It is important that any entity in an entity set
be uniquely identifiable.
• Practically, we use the values of certain
attributes to uniquely identify an entity.
• For example, when the clerk at a bank keys
in a customer’s SSN, the customer’s full
information can be brought up.
Customer-street
SSN

Customer-city

Customer-name
customer

• In this particular case, the value of the


combination of any attribute(s) with SSN can
uniquely identify a particular customer.
• Meanwhile, it is also obvious that some of these
combinations may have redundant attributes.

• Keys are very important part of Relational


database.
• They are used to establish and identify relation
between tables.
• They also ensure that each record within a table
can be uniquely identified by combination of one
or more fields within a table.

26
1.SUPER KEY
• An attribute or a combination of attribute that is
used to identify the records uniquely is known as
Super Key. A table can have many Super Keys.
• A superkey is defined in the relational model as a set
of attributes of a relation variable (relvar) for which
it holds that in all relations assigned to that variable
there are no two distinct tuples (rows) that have the
same values for the attributes in this set.
• Equivalently a superkey can also be defined as a set
of attributes of a relvar upon which all attributes of
the relvar are functionally dependent.
• E.g. of Super Key
• ID
• ID, Name
• ID, Address
• ID, Department_ID
• ID, Salary
• Name, Address
• Name, Address, Department_ID
• So on as any combination which can identify the
records uniquely will be a Super Key.
(II) Candidate Key 

• A candidate key is a field or combination of fields


that can act as a primary key field for that table to
uniquely identify each record in that table.
• It can be defined as minimal Super Key or
irreducible Super Key. In other words an attribute
or a combination of attribute that identifies the
record uniquely but none of its proper subsets can
identify the records uniquely.
• E.g. of Candidate Key
• ID
• Name, Address
• For above table we have only two Candidate Keys (i.e.
Irreducible Super Key) used to identify the records from
the table uniquely. ID Key can identify the record
uniquely and similarly combination of Name and
Address can identify the record uniquely, but neither
Name nor Address can be used to identify the records
uniquely as it might be possible that we have two
employees with similar name or two employees from
the same house.
• Candidate keys are defined as the set of fields from
which primary key can be selected. It is an attribute
or set of attribute that can act as a primary key for
a table to uniquely identify each record in that
table.
(III) Primary Key 
• a primary key is a value that can be used to identify a
unique row in a table. Attributes are associated with
it.
• In the relational model of data, a primary key is a
candidate key chosen as the main method of uniquely
identifying a tuple in a relation.
• A Candidate Key that is used by the database designer
for unique identification of each row in a table is
known as Primary Key. A Primary Key can consist of
one or more attributes of a table.
• E.g. of Primary Key - Database designer can use one
of the Candidate Key as a Primary Key. In this case
we have “ID” and “Name, Address” as Candidate
Key, we will consider “ID” Key as a Primary Key as
the other key is the combination of more than one
attribute.
(IV) Foreign Key 
• a foreign key (FK) is a field or group of fields in a
database record that points to a key field or group of fields
forming a key of another database record in some (usually
different) table.
• Usually a foreign key in one table refers to the primary key
(PK) of another table. This way references can be made to
link information together and it is an essential part of
database normalization
• The purpose of the foreign key is to ensure referential
integrity of the data i.e. only values that are supposed to
appear in the database are permitted.
• E.g. of Foreign Key – Let consider we have another
table i.e. Department Table with Attributes
“Department_ID”, “Department_Name”,
“Manager_ID”, ”Location_ID” with Department_ID
as an Primary Key. Now the Department_ID
attribute of Employee Table (dependent or child
table) can be defined as the Foreign Key as it can
reference to the Department_ID attribute of the
Departments table (the referenced or parent table),
a Foreign Key value must match an existing value in
the parent table or be NULL.
(V) Composite Key 
• If we use multiple attributes to create a Primary Key
then that Primary Key is called Composite Key (also
called a Compound Key or Concatenated Key).
• But any attribute that makes up the Composite
key is not a simple key in its own.
• E.g. of Composite Key, if we have used “Name,
Address” as a Primary Key then it will be our
Composite Key.
(VI) Alternate Key or Secondary Key 

• The candidate key which are not selected for


primary key are known as secondary keys or
alternative keys
• Alternate Key can be any of the Candidate Keys
except for the Primary Key.
• E.g. of Alternate Key is “Name, Address” as it is the
only other Candidate Key which is not a Primary
Key.
• TYPE OF OPERATORS
Data-type Syntax Explanation

Integer INTEGER The integer data type is used to specify


an integer value.

Smallint SMALLINT The smallint data type is used to specify


small integer value.

Number NUMBERP) It specifies a numeric value. Here 'p' is


precision value and 's' is scale value.

Real REAL The real integer is used to specify a


single precision floating point number.

Decimal DECIMAL(P,S) It specifies a decimal value. Here 'p' is


precision value and 's' is scale value.
Double precision DOUBLE PRECISION It specifies double precision floating point
number.

Float FLOAT(P) It specifies floating-point value e.g. 12.3,


4.5 etc. Here, 'p' is precision value.

Character CHAR(X) Here, 'x' is the character's number to


store.

Character varying VARCHAR2(X) Here, 'x' is the character's number to


store

Bit BIT(X) Here, 'x' is the number of bits to store

Bit varying BIT VARYING(X) Here, 'x' is the number of bits to store
(length can vary up to x).

Date DATE It stores year, month and days values.

Time TIME It stores hour, minute and second values

Timestamp TIMESTAMP The timestamp data type is used to store


year, month, day, hour, minute and
second values.

Time with time zone TIME WITH TIME ZONE It is exactly same as time but also store
an offset from UTC of the time specified.

Timestamp with time zone TIMESTAMP with TIME ZONE It is same as timestamp but also stores an
offset from UTC of the time specified.
+ It is used to add containing values of both a+b will give 150
operands

- It subtracts right hand operand from left a-b will give -50
hand operand

* It multiply both operand?s values a*b will give 5000

/ It divides left hand operand by right hand b/a will give 2


operand

% It divides left hand operand by right hand b%a will give 0


operand and returns reminder
Operator Description Example

= Examine both operands value that are (a=b) is not true


equal or not,if yes condition become true.

!= This is used to check the value of both (a!=b) is true


operands equal or not,if not condition
become true.
<> Examines the operand?s value equal or (a<>b) is true
not, if values are not equal condition is
true
> Examine the left operand value is greater (a>b) is not true
than right Operand, if yes condition
becomes true
< Examines the left operand value is less (a<="" td="">
than right Operand, if yes condition
becomes true
>= Examines that the value of left operand is (a>=b) is not true
greater than or equal to the value of right
operand or not,if yes condition become
true
<= Examines that the value of left operand is (a<=b) is true
less than or equal to the value of right
operand or not, if yes condition becomes
true
!< Examines that the left operand value is (a!<="" td="">
not less than the right operand value
!> Examines that the value of left operand is (a!>b) is true
not greater than the value of right
operand
SQL Logical Operators:
Operator Description

ALL this is used to compare a value to all values in another value


set.

AND this operator allows the existence of multiple conditions in an


SQL statement.

ANY this operator is used to compare the value in list according to


the condition.

BETWEEN this operator is used to search for values, that are within a set
of values

IN this operator is used to compare a value to that specified list


value

NOT the NOT operator reverse the meaning of any logical operator

OR this operator is used to combine multiple conditions in SQL


statements

EXISTS the EXISTS operator is used to search for the presence of a


row in a specified table

LIKE this operator is used to compare a value to similar values using


wildcard operator

You might also like