Dbms Notes
Dbms Notes
3
type and
Relational Data Model and Languages
appratoprtriibauhe
its
BELATIONAL MODEL CONCEPTs
relational model represents the
database as a
so) TE celation is thought of as a extent, a collection
we do sembles atable of values or to some of relations. Each
flat file of records. relation
is table of values, each row in the table
related data
do useful collection ofcorresponds tovalues. row in the table represents
In relational model each
wehich areal-world entity or represents
relationship. The table narme
mn names are used to nelp in and
ations. eremple, in the table STUDENT, cach row interpreting the meaning of values in each row.
gram. ent entity, All values in a column are of the represents facts about a particular
same data type.
by socia ROLL NO
ch course NAME 01234
CLASS
BRANCH
AMIT
For cad AJAY 01235
B.TECH CS
aints hold In the formal relational model terminology :
B.TECH CS
eing mus Row = Tuple, Entity
nost recen Column = Attribute
= Relation, Entity set
ubsequen Table
Domain =Set of values that can appear in each column
Some important terms with respect to the relational model are now defined
(1) Arelational schema can be thought of as the basic information describing
y cours atable or relation. This includes a set of
column names, the data types
associated with reach column and the name associated with the entire table.
s jointly For example, a relation schema for the relation called Students could be
lodel this
sary.
expressed using the following representation :
by ssn Students (sid: string, name: string, login : string,
ame and age : integer, gpa: real)
There are five fields or columns, with names and types as shown above.
ributes)
(2) A relationa! database schema is a collection of
;a child relation schemas,
assum describing one or more relations.
ested in (3) Domain is synonymous with data type. Attributes can be thought of as
columns in a table. Therefore, an atribute domain refers to the data type
associated with a column.
n two?
SQL is widely used query language in relational database systems and is discussed in detail in chapter 4.
However, in this chapter authors have taken liberty in giving examples using SQL. Whenever the reader
JU fnds mention of SOL, that portion can be deferred to be studied later on when the reader goes through
the next chapter.
DATABASE
3.2
(4)
MANAGEMENT SLATIONAL DATA
Arelation instance is a set of tuples (also known as rows or recor
each conform to the schema of the relation.
cardinality is the number of tuples in the relation
(5) The relation
(6) The relation degree is the number of fields (or columns) in the rel,
Summarizing. we can say that the relational model is a way of looking Doma
More precisely, the
lf defines how to represent and manipulate data. relational
is concermed with three aspects of data data structure, data integrity
manipulation. NOT NULL
r to enter nul
Syntax :
3.1-1 Characteristics of Relations
Every relation has some characteristics that make it different from a fl
characteristics are : Example
Ordering of Tuples in arelation : Arelation is defined as a set of tuo CREAT
tupies in a relation do not have any particular order. However, in a file, reco
physically stored on disk so there is always an order among the records. This a
indicates first, second, ith and last records in the file. Also, the rows are dis
in a certain order. Tuples ordering is not a part of a relation definition bec ):
relation attempts to represent facts at a logical or abstract level. (b) CHEC
Value and Nulls in the tuples : Each value in a tuple is an atomic vastraint. It en
means tuple is not divisible into components within the framework of the Syntax :
relation model. Hence, composite and multivalued attributes are not allowed. [CONSTR
The value of some attributes within a particular tuple may be unknownt Syntax :
not apply to that tuple. A special value called NULL is used for these cases. [CONST
Interpretation of a relation : The relation schema can be interpret Example
declaration or a type of assertion. CREATE
(
32 INTEGRITY cONSTRAINTS
This is the mechanism which is provided to prevent invalid data
entry into
Only if certain conditions are satistied, then the data can be stored in the thda _ Entity
The purpose of these constraints is to ensure that there no The enti
due to changes made to the database by the authorized usereloss in data connary key an
Constraints can be given at table level or column level irantees tha
Constraints can be divided into the following types : primary ke
unique id
ue within a
GEMENT
s Ot recorda
SJELATIONAL DATA MODEL AND LANGUAGES
3.3
CONSTRAINTS
lation.
in the rela
f looking Domain
Entity Refe. ntial
(b) Primary Key : Primary key is the unique identifier of the rows in a tabe
Also
It ensure the uniqueness of the records.
It does not accept NULL values.
It can be defined for single column or multiple columns. When we
defining it for multiple columns, it is called composite unique key.
It can be at table level or column level.
Syntax: At table level
(CONSTRAINTS] |CONSTRAINTS_NAME] UNIQUE
(COLUMNNAMEI COLUMNNAMEN]
Example :
CREATE TABLE PRIMARY_TAB
EMPNO NUMBER(7),
EMPNAME VARCHAR2(20)
CONSTRAINTS UNIQ_COMPPRINAARY KEY (EMPNO, EMPNAME N
fo
iction in e
bute Canne
RELATONAL DATA ANE ANp
LANGUAGES 3.5
Syntax: At coumn evel
(CONSTRAINTs] CONSTRAINTS NAMEL (CONSTRAINTS_TYPE)
Example
assigned CREATE TARIE PR) TAB
EMPNO NUMBER(7) CONSTRAINTS PK
EMPNAME VARCHAR2(20) PRIMARY KEY.
When de ).
3.2-3 Referential Integrity
This con straint is uscd to establish a
relationship between parent and
or is used to establish a
relationship between more than one table. To child tables
relationship, which column is to be sclccted to create that relationship. it establish
is regquired
a
that this column has the same data type in both tables and the size is also equal. Also.
this column should be either a primary key or unique in parent table.
We know that in the relational data model, associations between tables are
defined using foreign keys. A referential integrity constraint is a rule that maintains
consistency among the rows of two tables (relations). The rule states that if there is
a foreign key in one relation, either each foreign key value must match aprimary
EMPNA key value in the other table or else the foreig1. key value must be nul.
If base relation (table) includes a foreign key FK matching the primary key PK
of some other base relation, then every value of FK in the first table must either be
S_TYPE, cqual to the value of PK in some tuple (row) of the second table or be wholly nul
(that is, each attribute value participating in that FK value must be null). Or in other
words, a given foreign key value must have matching primary key value in some
tuple of the referenced relation if that foreign key value is non-null. Sometimes, it is
necessary to permit foreign keys to accept nulls. Here it must be noted that the null
QUE. are of the variety 'value does not exist' rather than value unknown'
Example :
SQL > Create table parent
Ows in at
Deptno number(5) primary key,
Dname varchar2(20),
Location varchar2(15)
When )
ue key. sQL > create table child
(
Empno number(5) primary key,
Empname varchar2(15),
Job varchar2(10),
Mgrmo number(5),
Deptno number(5),
References parent (deptno)
Note : Here we are not using foreign key. The keyword references are working as a
EMPNA foreign key.