0% found this document useful (0 votes)
12 views5 pages

Dbms Notes

Uploaded by

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

Dbms Notes

Uploaded by

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

ENT SYSTE

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

Domains, Attributes, Tuples and Relations


A domain D is aset of atomic values. Atomic means
that each Val. 2-1 Domain
concerned. All the val
domain is indivisible as far as the relational model is
A) is made up of relatin: Same domaim
A relation schema R denoted by R(A|, A2. , a "OMAIN stater
Each attribute A; is the name of
R and a list of attributes A,, As. .... A,,.
by some domain D the relation schema R. The egree (o ary o a rela a) NOT N
the number of attributes n of its relation schema.
role|iheALTERL

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

nteregrilattiyonaland NOT NULL Check


Unique Primary Key
Foreign Key

2-1 Domain Constraints


each value All the values that appear in a column of a relation
of Lm domain. Domain constraints can be specified by(table)
meansmust bethetaken from
CREATE
e of arelation SOMAIN statement and can be added or dropped from existing domain by means
) of a
rela
roleDF the ALTER DOMAIN statement.
(o) NOT NULL: It enforces the user to enter some value. It will not allow the
ser to enter null values.
Syntax :
[KEYWORD]
Erom a file.
[CONSTRAINTS_NAME) [CONSTRAINTS_TYPE)
Example :
set of tuple CREATE TABLE NOT_NULL
a file, recon (
rds. This om EMPNO NUMBER(7) (CONSTRAINT NN NOT NULL).
ows are disp EMPNAME VARCHAR2(20)
inition beca ):
(b) CHECK : It will check the range from value for the column with check A
atomic vabnstraint. It enters the value if operation succeeds else not.
ork of the Syntax : At table level
[CONSTRAINTS][CONSTRAINTS _NAME)check [column name Condition]
ot allowed.
unknown o Syntax : At column level
ese cases. [CONSTRAINTS] [CONSTRAINTS_NAME]check [column name Condition)
Example:
interpreted CREATE TABLE CHECK_TAB
(
EMPNO NUMBER(7)CONSTRAINTS CH CHECK(EMPNO>70),
EMPNAME VARCHAR2(20)

atry into the2-2 Entity Integrity


d in the dat The entity integrity rule is designed to assure that every relation has a
data const imary key and that the data values for that primary key are all valid. Entity integrity
Larantees that every primary key attribute is non-null. No attribute participating in
eprimary key of a base relation is allowed to contain nulls. Primary key performs
e unique identification function in a relational model. Thus, a null primary key
due within a base relation would be like saying that there was some entity that had
3.4
DATABASE MANAGEME
An entity that cannot be identified is a
PELATIONAL

no known identity. Synta


hence the name entity
integrity. In some
assigned a data valve. There are
cases, a
two situations where contradiction
particular in ter
this is likelyattrtoibute cannot Exam
There is no applicable data value occur CREA
Applicable data value is not known when the values are (
(a) Unique : assigned
It maintains the uniqueness of the records.
it accept NULL values also.
I can be defined for a single column or multiple column. When def.
3.2-3 Ref
on multiple column, it is called composite unique key. This
It can be at table level or column level. or is used
Syntax : At table level relationsha
[CONSTRAINTS] [CONSTRAINTS_NAME] UNIQUE that this C
[COLUMNNAMEI COLUMNNAME) this colu
Example : We
CREATE TABLE UNIQUE TAB definedu
( consisten
EMPNO NUMBER(7), aforeign
EMPNAME VARCHAR2(20) key value
CONSTRAINTS UNIQ_COMP UNIQUE(EMPNO, EMPNAME If t
): of some
Syntax : At column level equal to
[CONSTRAINTS] [CONSTRAINTS_NAME] [CONSTRAINTS_TYPEJ. (that is,
Words,
Example: tuple of
CREAE TABLE UNIQ_TAB
( necessan
are oft
EMPNO NUMBER(7) COSNTRAINTS UNIQ UNIQUE,
EMPNAME VARCHAR2(20)

(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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy