Professional Documents
Culture Documents
DBMS Minor Exam Notes in One PDF
DBMS Minor Exam Notes in One PDF
daba)
Having undensiood Jhe Concept o6 database (collecion of velahed
and ushy do We need database (fer esfcienty Solviy a problem
Nlow We,
oiu shedy what is DBMS.
B Data
Data
M Daa
(usen Daba
4sey Comnnicate to S Daba
bBMS interfac. for
efhient and faster
Diff Progpam
Cocle to in sert Daabase
way os Guil th Aling his dalet, update
Crd quoy dateubane
Tequivemont
infovmahon
prvides Qn
intonface to þei7otm vasous operchbny
liKe daabase Creahon, Serinr data updakns, doleiny data,
L poonden rolechon nd Secuihy to Jhe databane
DeMS’sohuane /managemont of daabase
Allows usen the follootng tas Ks.
(a)
CDaa. definahon : Used for cieahon , modiffcaion cand
that doGnes dhe
definihon -hat 7anizohen t
Temova o
Ihe daa
(o) Dala up daion.. Used for insenhon modifaakon ond cdeleion
aChual dala database
Tehievent data fom cdakaban
Daa retieval: used for
L All MOdean bBMS hke SQL, MYSQL ^eve , lBs DB2 yacle and
micYosot aC Ces based On ROMS
Based on, selahonal data model DBMS for veahonal(table)
L Al opeyahono liKe in Sert dolota "ane þergomed on
tables
Data is Depre Sented in tesm ok tuply CoLos) n RDBMS
Due. o a Collechon of oYganized Ser oG tables, dae
Can be accened eanily in RDBMS
4
Records
Emp_i E Name Post Salay
tuples Rahul Cleik D0,000
E2
Rows
or Kapil Managen 80, o00
E3 Mukesh clenk 20, o00
E4
Manoj leon Lo, od0
E5
Radha 80, o00
E6
Shweta Manajea
Clik 20, o00
|File syslem
f-J
disk
file sysla
Hand dis
fle Syston but we ane wsiny D8MS
not emoved
We hawe
Jhe sota. moree etiieny.
to manaye
et take an eyample ! oc Shdont data in nvasiy
tneis O6 dBMS
what e dhe domeiG of Ale syslem
shucluved data pyecdetined ’ easy data
acle
File sysem daa ype is
( stuched data. ’
DBMS
Matl ilems arayemont
Road ije nalage Acodeni,
cifferent sechon ( Acco DD- MM- YYYY
Diff pepk Date’
kollow dif. (onak MMa DD -YYYY
may utich Con MM- yy- DD
ile bamed sysonm
inconsisleney qlso YY- DD- My
(ead to clala
have stuolned data
DBMS we
but in
Data models in DBMS help to understand the design at the conceptual, physical, and logical levels as it provides a clear
picture of the data making it easier for developers to create a physical database.
Data models are used to describe how the data is stored, accessed, and updated in a DBMS. A set of symbols and text
is used to represent them so that all the members of an organization can understand how the data is organized. It
provides a set of conceptual tools that are vastly used to represent the description of data.
The hierarchical data model is one of the oldest data models, developed in the 1950s by IBM. In this data model, the
data is organized in a hierarchical tree-like structure. This data model can be easily visualized because each record in
DBMS has one parent and many children (possibly 0) as shown in the image given below.
A network model is nothing but a generalization of the hierarchical data model as this data model allows many to many
relationships therefore in this model a record can also have more than one parent.
The network model in DBMS can be represented as a graph and hence it replaces the hierarchical tree with a graph in
which object types are the nodes and relationships are the edges.
(c) Entity-Relationship Model (ER Model)
An Entity-Relationship model is a high-level data model that describes the structure of the database in a pictorial form
which is known as ER-diagram. In simple words, an ER diagram is used to represent logical structure of the database
easily.
ER model develops a conceptual view of the data hence it can be used as a blueprint to implement the database in the
future.
Developers can easily understand the system just by looking at ER diagram. Let's first have a look at the components
of an ER diagram.
Entity - Anything that has an independent existence about which we collect the data. To learn more about Entity in
DBMS click here.
They are represented as rectangles in the ER diagram. For example - Car, house, employee.
Entity Set - A set of the same type of entities is known as an entity set. For example - Set of students studying in a
college.
Attributes - Properties that define entities are called attributes. They are represented by an ellipse shape.
Relationships - A relationship in DBMS is used to describe the association between entities. They are represented as
diamond or rhombus shapes in the ER diagram.
In the above-represented ER diagram, we have two entities that are Employee and Company, and the relationship
among them. Also, in the above-represented ER diagram, we can see that both the employee and company have some
attributes and the relationship is of "works in" type, which means the employee works in a company.
(d) Relational Model
This is the most widely accepted data model. In this model, the database is represented as a collection of relations in
the form of rows and columns of a two-dimensional table. Each row is known as a tuple (a tuple contains all the data
for an individual record) while each column represents an attribute. For example -
The above table shows a relation "STUDENT" with attributes such as Stu. Id, Name, and Branch which consists of 4
records or tuples.
As suggested by its name, the object-oriented data model is a combination of object-oriented programming and
relational data model. In this data model, the data and their relationship are represented in a single structure which
is known as an object.
Since data is stored as objects we can easily store audio, video, images, etc in the database which was very difficult
and inconvenient to do in the relational model. As shown in the image below two objects are connected with each
other through links.
In the above image, we have two objects that are Employee and Department in which all the data is contained in a
single unit (object). They are linked with each other as they share a common attribute i.e. department_id
(f) Object Relational Data Model
Again as suggested by its name, the object-relational data model is an integration of the object-oriented model and
the relational model. Since it inherits properties from both of the models it supports objects, classes, etc like object-
oriented models, and tabular structures like the relational model.
Schona.
o6 Coect
aSeloct Comnicar
olaa
aCCos fer
tool
hendy Dhis
intenaci'
on pla
the
oncoos
opt clone d'Yectly
Con DBs
need
we for pialtesm
example
DBMS
wjh be ony
A (maion) infoahon
to uned
DBMS clisecty lnguoye
Usen Cen Fr ’
tontmanagement.
.claba,
impor Jawa
languaye
cny
(in
Conci
the on auchiechye&
de.
of Databne qpplicai Aexpcundimacine
client
any for
Data to oiee cloest
ibel,
94
local JDBeCinrochi
Arehieie it
Cihical available.
he91e for
DBMS/ a9chitechuve
Arei
techm o Seswer ne.
dalab
Java
is Av
ajsechve e dovelomeat Senu
en(client- ODBC1
trekilec done. se i
DBMS dotcba
og ctiyecHy for Ofhce
Ms
eq. Lwe
Can
use
ce fAient Jhe
3Tie Oot Hen Any
changes Suilabla dclaloou onlyWe
veVS far open
to
a DBMS|tie1
- her darabana aychitecwe
Syslemcho ^ecuvely. ie Dalabone
aachilecve
2Ties
ano inmducicn le store NO-
wed applicahong
todays AP's
for 2
3
ODBC
File
dalabse Same
-’ San and
quicuy Types
aMchilechYe
(a)
1-
tie
Lec-I -a
lec
Ly
Lot
w A
(0) 2)
Seswes
Serven
Sowe
aComecie cient Cnd
Cient
SeweN
oih
Senven Clieat
utich
rovlhen
cemuicat
cala
cat teracli
Comeni
esryishon Deskto
papplicaiony atni
|Applitaion in 1Appl
SeveN
S
DBM Dalaba Use
USe loyen end
no
hen web
clive
cty
aicaon ent
cli
lape
Can
h
side.
ey
ampleg
’ 3-
Tien
Arclilecue aken for
on
Applic
clien
Conlai
Seyen used
chent
L
L
L
enG colvefi.
velayonl
in
dalclane Canephod
Schene, stchne
clala
Ohone
uhia
Sysle
m dechni
dala ancd
name
of orgomized objec inced
held
o
vepvenonlei oG
pant to schema typically
Cyel
Snvolved.
dalabou
Schem
Schema
be Compan
teguivemo
projeck
ARCHITECTU
RE Schome dotonengm
Conshci
tubte Synax
luds
inc
logicad co
not
Cogical
databan ure Cne
Less
clean,
cbstact
aban
pic houwbu'snen
ruler
inkpiy
dal Ihey
DBMS physicad big wwually
iniil JheySueh
SchemaConcepul Cisntin
offers
phys'cal:
MonuE-9 y
Ls Conaphal Cogicad
Concept
(a)
Lec-3
Lec-4’ Lec-2 Lec
Schemna ’
for
Extenal
schema
aMchiechures D3MS
hhat is
ConcoptDBMS File
Quwshion
Aie Sys
Stou
chye ok lem
table
Slore Schema Vs
ue 20 Houo CEPTUAL
CoN
PHYsICAL tencQ Ex DBMS
soye SCHEMA
ScHEMA cro
table
Jhen Jha dhe
iim-acjn.
Anit Schema Lec-y
d wtich Jhyee
data data
above
(ouel
Cin yn
clale
(Etupkat,
çomaion) ER schona
o Ralaliaad Extesna
Can
in Schemos
Amozon, stuce anchece.
tables, whc cismbuta
Conwoli3el
con ke be. .
Pad
is s
tove CPhysiSntesnal
cleau)ue) togicadCaue
schema
Jhen Jhe Qm
ele:) in level)
yied
struchye to
Usig
Y)
6
to
lo
isinkomain
Lha acce
Cant
inteact
skoved ciff. uew
dat
isfer is lno)
do Afendonce (
indepencone
data
and
Usen ca
fenont Wedile.Schema
diyecHy vieos.
mls poic,
(ees
Ahoyh Cevel pasuoord Use
ale
for c
he
Mol
peon
on
sn
manu
physicoll, per exten
vole
Don 2e ot
Jhe w
data View
ord View
(for it
fomm uthee om: manls Shudet
foViecs yne
(heu to
or dau ys login
fepyesent
icd
(acug
Saefor cifforuntTfaculg login sJhat
is
the
Use)
utich mana. Unedin
pafe
knoe schoma kils Role
Selec
avels 9n stoved
is Shou.
toHo0 A shown is
evel
Jhvec Sloved, F8 shudent
coñ GnmaiL
f.
Unive1sil new
Jis
But
made wtonee
Extenal vieuhuder
S we
See
USen
is Take
when
we
No
#Why e
2 solaianhip
a /shems call, lo (reymen.
mauy
telaionlp. tieh Cie)
schema
Extenal
physi
fiw
Concenheel
viesschoma mods
fere to schoma
Physicod
alh
enhien
bu be Rolaicnal is data,dise,chjie le
DBMS)
(Cayen
bluepink daba eh cMow schema
Concephol
in
Tables istorad
ele
). INRo
Jhe decid,
Dnd
ondl
Schoma
ER
,Age. dale
stoyod
isdata male
atmin
Dabon
lelahonal
Moclel dala ia
DB’
Achl
Concopheal
schorna Roll
no)
Moclol o6 schoma inten
(au Admin
palabo
doisner
Bavah
an
deignen
Usen
See
exampe
dabab
an
HowSudont
Wehue
to ER cal bu
physi
she
So :NOTE
e. *
3
DBMS Architecture
• The DBMS design depends upon its architecture. So, DBMS architecture depends upon how users can connect
to the database to meet their requirements.
• The architecture of a database management system plays an important role in determining the actual design and
layout of the database
• To understand the DBMS architecture, you must have a clear idea about the client and server. The client is the
user requesting service, in this case, access to the data stored in the database. The server side is the side that
answers the request of the client.
•The user directly interacts with the database itself, which means that it is accessible to the user to create, alter or
delete the data
•In simple words, in 1-tier architecture, the user can directly sit on the DBMS and uses it.
•1-tier architecture is rarely used in production. It is used where the quick response is required. For example,
development of the local application
• The user directly sits on the database, and there is no layer between
the user and the database. Therefore, there is no data abstraction; the
whole data is available. There is no interactive user interface.
ODBC:
JDBC:
•But problem with this architecture is scalability. Scalability means when the number of users increased then two-
tier architecture does not work properly.
•Security is other main problem because It does not allow the role base access. It means author can work as
administrator because every client has direct and similar access to database.
•Traffic load on database server is high because it first processes the query and then provides the required data
as well.
Example of 2-TIER AND 3 TIER ARCHITECTURE: Ticket counter and IRCTC , Bank counter and online banking
3-Tier Architecture
•In 3-tier architecture, client cannot directly communicate with the database server. It contains another layer
(application layer) between the client and server.
•The user on the client-end interacts with an application server (also called business layer) which further
communicates with the database system.
•End user has no idea about database and database also has no idea about any end user. The 3-Tier architecture
mostly use in web application.
• Any modification in the data done by the user does not directly affect the database itself. The changes are first
performed on the application layer. There is no real connection between the database and the user.
• The query processing and other functionalities of the database management system are performed at the server-
side application.
• It allows the DBA to manage the access of the various users. It also enables concurrent transactions on the
database.
3-Schema Architecture
The three schema architecture divides the database into three-level to create a separation between the physical
database and the user application. In simple words, this architecture hides the details of physical storage from the
user. The database administrator (DBA) should be able to change the structure of database storage without affecting
the user’s view.
This architecture contains three layers or levels of the database management system:
• External level
• Conceptual level
• Internal level
Three schema architecture hides the details of DB from the user. It’s other name is three Level of Abstraction.
The database administrator should be able to change the structure of database as according to need, without
affecting the user’s view. This effective three schema architecture holds 3-layers as below
•External or view level tells the actual view of data that is relevant to the particular user.
•View/External level provides different views of the same DB for a specific user or a group of users. For example
view for faculty student is different than faculty admin.
•External level develops with the help of front end programming (Javascript, HTML etc)
•An external view provides a powerful and flexible security by hiding some information of the database from a
particular user.
3-Tier Architecture
2. Conceptual or Logical level
•The logical/conceptual level tells the structure of the entire database.
•Conceptual level acts as a intermediate layer between the physical storage(DB) and external level.
•Database designer works on this layer which provides the structure of database.
•Database any model (i.e. Relational or ER Model) can use at this level which provides the structure of database.
i.e Gmail makes changes in conceptual and physical schema at regular basis without changing the user view.
Schema and Instance
•The collection of information stored in the database at a particular moment of time is called database
instance.
•The overall design or structure of the database is called database Schema
Types of Schema
The different types of schemas are as follows −
•Physical schema − It is a database design at the physical level.It is hidden below the logical schema and can be
changed easily without affecting the application programs.
•Logical schema − It is a database design at the logical level. Programmers construct applications using logical
schema.
•External − It is schema at view level. It is the highest level of a schema which defines the views for end users.
Schema and Instance
Database Languages
Database Languages
Database Languages
Database Key Features
Database Key Features
lopic: ER (Enkky- Relakonship) Tiagaam
the research pape)
. ntodu ced by Dr. Petey chen in l976 (You Can check
( inglana/dat
ER diagsam ag it is
Can not be tepresented
in an
Enhy in ER diagrOn
Enkhy set is vepesented by ectangla
Relahonal Model
Enky ah be eprerented by ow/ uple.in Yelahonal modol
( Enky Set s Tepveenhed by table
Studenbt
Rollas Name Age.
one enil
Roll No
Nae
18
anohen enil 3
Student
S
his is an enht Set
´Set of all 20
enikes is 18 dont
Cauted enity set ER Mocle', we
Shudent able is an eniy set. Inset cak only Visucl
epyenenkaho. (iogcal schema)
enhy Can net be yepvenentad inn
ER diagvam
Types of enhy set
.enhy
Weak enhy
Let w
mas und ond Jhe Secomd omporo ot ER madal
(b) Athi buteg Athibuten in Qn ER diagram is Jhat Componenb
Jhat descibe Jhe chavacerisie, enhie,.
ER diagra m Athibutes ane Tepye sented an ellipse ot oval shape
Sn elahonal mod e!, AHibui Yepvenenlad Sepavat Columng.
for each eniy we dyaw a table
a elqhonad modol.
fov each atmbub we cdd exha Column
Shudenk
phone nt
(Roll NO D.0. B
(f-name
ame Studen t
(m-nan
Types os Atributey :
Simple nd Composite Atibulin
Simple Cannot ke diided Guyhe
sepresented by Gimpl 0va shape
C omposite atibuli Can be divjded GUyhen in
reptenenlad by Oval Connecto to nothno o¯a. Simple atibute.
Simple Roll NO.
ComposileeBe 9 Name, Addve.
9n velaioncu mode! Corposi le. ahbur epyencnsed an Separaa o lumng
) and
single ’ Cqn Muilivalued AHnbue
haue ’ can have mote
Dny one Value
Jhan ona value.
enhhy
S
T Sg
Degree
L Candialiy
3
student Cou re
Quateinauy
CAROINALITIGS Jhe mumbeg O6 ime an enhhy ot an eniy Set
1 1 feale
male maried
to
Can e Yeprerened an
using Sets )
A B
À2
M
Sjenist Kinee
Av
Many-to-one !
when enkhes in one
enthy Set Can ta ke
part only onCe Sn the Telahonshi'p Set and nhhe in
othey enhy Set Can take pant more Jhon on Ce in Jha
M
Student
sets Can
be represertad by
B
A
A
2 B2
A :
Au
A2 2
A3
A4
* ParhodpaHon Constyaint
Specities whealhen the exislen ce o an enty depend,
elated to anothei enhy uia a Delahonship ype.
being and maximu m
Ly Jhis minimum
Conshaint Specity dha each enky must/Can
umben of telahons hip io tan os Jhat
panhipate
Project Enplose.
many relahonhip
Jhi's Conshaint Spec (be o how uek
Sn Simply Language exiStena in
inolan enhy mwt hawe max,
database. Jhe enhhy may have
Can ACWe.
'mik of Teloenship it
M Employea
|Projeck (o,22
(3 smaX
Ey
tae 4 Inter
eg. Real life Supenssa Can
sudot
Roll No,
step- 4: M 9nshnch
from Depavnon hw
from depart to tnomeel
3h is 1 to Many Yelahowip
*
fom JDepaanod
haodad 9nstucta
by
M M Cowrse.
DeFavhru!
M Cour
fom ) Snstect by
M M Cows
fom shucent enToll
Nouw
Jhe Complet ER diagm
nae
D_ NO Cocai
Deportrou heal
Co No
Iname
name han
DoB
Pie-vepuisb
shuden
S-emei
Roll No S.name
DoB.
ER Model notes from internet source
An Entity–relationship model (ER model) describes the structure of a database with the help
of a diagram, which is known as Entity Relationship Diagram (ER Diagram). An ER model
is a design or blueprint of a database that can later be implemented as a database. The main
components of E-R model are: entity set and relationship set.
An ER diagram shows the relationship among entity sets. An entity set is a group of similar
entities and these entities can have attributes. In terms of DBMS, an entity is a table or attribute
of a table in database, so by showing relationship among tables and their attributes, ER diagram
shows the complete logical structure of a database. Lets have a look at a simple ER diagram to
understand this concept.
A simple ER Diagram:
In the following diagram we have two entities Student and College and their relationship. The
relationship between Student and College is many to one as a college can have many students
however a student cannot study in multiple colleges at the same time. Student entity has
attributes such as Stu_Id, Stu_Name & Stu_Addr and College entity has attributes such as
Col_ID & Col_Name.
Here are the geometric shapes and their meaning in an E-R Diagram. We will discuss these
terms in detail in the next section (Components of a ER Diagram) of this guide so don’t worry
too much about these terms now, just go through them once.
Components of a ER Diagram
As shown in the above diagram, an ER diagram has three main components:
1. Entity
2. Attribute
3. Relationship
1. Entity
Weak Entity:
An entity that cannot be uniquely identified by its own attributes and relies on the relationship
with other entity is called weak entity. The weak entity is represented by a double rectangle.
For example – a bank account cannot be uniquely identified without knowing the bank to which
the account belongs, so bank account is a weak entity.
Weak Entities
A weak entity is a type of entity which doesn't have its key attribute. It can be identified
uniquely by considering the primary key of another entity. For that, weak entity sets need to
have participation.
In above example, "Trans No" is a discriminator within a group of transactions in an ATM.Let's
learn more about a weak entity by comparing it with a Strong Entity
Strong entity set always has a primary key. It does not have enough attributes to build a
primary key.
It contains a Primary key represented by the It contains a Partial Key which is represented
underline symbol. by a dashed underline symbol.
The member of a strong entity set is called The member of a weak entity set called as a
as dominant entity set. subordinate entity set.
Primary Key is one of its attributes which In a weak entity set, it is a combination of
helps to identify its member. primary key and partial key of the strong
entity set.
In the ER diagram the relationship between The relationship between one strong and a
two strong entity set shown by using a weak entity set shown by using the double
diamond symbol. diamond symbol.
The connecting line of the strong entity set The line connecting the weak entity set for
with the relationship is single. identifying relationship is double.
2. Attribute
An attribute describes the property of an entity. An attribute is represented as Oval in an ER
diagram. There are four types of attributes:
1. Key attribute
2. Composite attribute
3. Multivalued attribute
4. Derived attribute
1. Key attribute:
A key attribute can uniquely identify an entity from an entity set. For example, student roll
number can uniquely identify a student from a set of students. Key attribute is represented by
oval same as other attributes however the text of key attribute is underlined.
3. Multivalued attribute:
An attribute that can hold multiple values is known as multivalued attribute. It is represented
with double ovals in an ER Diagram. For example – A person can have more than one phone
numbers so the phone number attribute is multivalued.
4. Derived attribute:
A derived attribute is one whose value is dynamic and derived from another attribute. It is
represented by dashed oval in an ER Diagram. For example – Person age is a derived attribute
as it changes over time and can be derived from another attribute (Date of birth).
E-R diagram with multivalued and derived attributes:
3. Relationship
Cardinality: Defines the numerical attributes of the relationship between two entities or entity
sets.
When a single instance of an entity is associated with a single instance of another entity then it
is called one to one relationship. For example, a person has only one passport and a passport is
given to one person.
When a single instance of an entity is associated with more than one instances of another entity
then it is called one to many relationship. For example – a customer can place many orders but
a order cannot be placed by many customers.
3. Many to One Relationship
When more than one instances of an entity is associated with a single instance of another entity
then it is called many to one relationship. For example – many students can study in a single
college but a student cannot study in many colleges at the same time.
When more than one instances of an entity is associated with more than one instances of another
entity then it is called many to many relationship. For example, a can be assigned to many
projects and a project can be assigned to many students.
A Total participation of an entity set represents that each entity in entity set must have at least
one relationship in a relationship set. For example: In the below diagram each college must
have at-least one associated Student.
Steps to Create an ERD (E-R Digram)
Following are the steps to create an ERD.
DBMS Generalization
Generalization is a process in which the common attributes of more than one entities form a
new entity. This newly formed entity is called generalized entity.
Generalization Example
Lets say we have two entities Student and Teacher.
Attributes of Entity Student are: Name, Address & Grade
Attributes of Entity Teacher are: Name, Address & Salary
These two entities have two common attributes: Name and Address, we can make a generalized
entity with these common attributes. Lets have a look at the ER model after generalization.
The ER diagram after generalization:
O1
Employee Table
ID No. Name Adhan no saly phene email Ahibue
ASupen Key
denh6ty Jhe tuple (athhbule orT sek-o( aribuka, )
Uniquely oho deucb)
tilo Super se C fom uhe Keys onu
Primany Key
1 Now we hove fo llouain 9 Cand'ddat Key s
Primany Key ID
AlOTE
Jhe WILQ be only One Pri mang key in a. table
DBA hauwe to
L |chose Cave(ully| pimay Keys om
set 06 Cardudat Keys
Neven oY
Vexy arely changeo
L Candi' dat
eys wi h NUL Value
Keys NOb a
Pnmay Key.
ALTER NATE KEYS: 4
9n n he Se o Candidat Keys hawe choSen
One Key aD pmmay ey cund e t Candidals Koygs
wi be Coulled alkeinau keys
Supn
Caidal
Primony PrimaA)
oy Prony
Foveign Key
NOTE: ORDERS Table is taking
i)Jhe usen id a Hibut oG
anoho table.
6eenona from prima Kay o
) Domdin Conohaint :
De kines Jhe clomain ot Valid (set of Values ) o6
ahhbuhe
shoud be tve inteçe.
should not e rnegah ve
should no be chavacen.
|0 2. Rohan 33 DI
103 Sohan 24 D2
Dohan 22 D3
’Pimay Key Porelgn Key in Rejoneniny table
Deparmonlal Table
Dep No LOcahon No O6 emplo
Humba 200
DI
133
D2 Agra
600
D3 Beryal
in ReterDnced able.
Primay ey
NOte.
L’
We. cant add D5. Jin Dep. No bE Employe. table becane
Jhot athib is detirod a toreign ay kich is taking
Yelerre 6rom Deposmonas Table Dep No
Al values Preront in Tejeenty table m t bo.
pveront in
(Fovein Koy)
Pirauy Kay table Ohenolse NULL' Can bo put in toreign Kay Jabu
Jhe Rulen
from pnmay key thble
6 malchin
) You cañt detete a ecord
records exists elqted table (teterenCad tabl)
value jn
2) You Cant [Change pimay Key
Ye Cord
has Te<aled recordy
fovegn Koy held if
ta bl. Jha
value in
3) You Cañt 9nsert
but you Can put
exis- in primos Kay
( NUL in Foveign Koy tabe.
KEY CoNSTRAINT:
Candicdct Key
An enhy Set Can houe mUliple Keys be Jhe
but wfich one Key
Foreign Key:
Foreign key is/are column(s)/attribute(s) of a table that point to the primary key
or candidate key of another table. They act as a cross-reference between two
tables.
Foreign key creates relationship between two tables. It helps to maintain data
integrity which is known as “Referential Integrity Constraints”.
Foreign Key
Referencing/Related Table
Table2: employee_info
emp_id emp_name emp_dob emp_city dept_id
10001 Rakesh 11-Mar-1990 Gorkahpur 101
10002 Shyam 03-Feb-1980 Lucknow 103
10003 Mahesh Sharma 01-Aug-1991 Gorakhpur 101
10004 Reena 25-Feb-1990 Prayagraj 103
10005 Amit Sharma 08-Jul-1992 Lucknow 104
10006 Rakesh Kumar 04-Apr-1989 Gorakhpur 104
Prepared By
National Institute of Electronics & Information Technology (NIELIT), Gorakhpur
राष्ट्रीय इलेक्ट्रॉनिकी एवं सूचिा प्रौद्योनगकी संस्थाि ,गोरखपुर
It means that dept_id field of employee_info table can have only those value which
are present in dept_id field of department_info table.
Primary key cannot be NULL; on the other hand foreign key can be NULL.
The foreign key field can have only those values which are present in primary
key field of another table.
The values of Primary key are always unique while foreign key field can have
duplicate values.
There is one and only one primary key in a table, but we can have more than one
foreign key in a table.
--------------------------------------------------------------------------------------------------------------------
Exercises:
Prepared By