1. DATA BASE KEYS
A key is an attribute (or set of attributes) that uniquely
identifies any record (from tuple).
EMPLOYEE (referencing/child/foreign/related)
{empid,name,adharno,email_id,deptid}
Emp_id NAME ADHAR
NO
Email id Dept_id
12345 a 11 ab 1
2 a 22 bc 1
3 b 33 cd null
Department(referenced/parent/primary/master)
Dept id loc
1 del
2 kol
3 mumbai
Super keys
Emp id,
Adharnumber
Email id
Emp id, adharnumber,emailid
Adharno , email id
Emp_id ,adharnumber
Empid , name , departmentid
Empid,name,adharno,emailed,deptid
2. Purpose
Key is used to uniquelyidentify any records or row of data
from the table.
It is used to establish and identify relationshipbetween table.
Super key-
A super key is a combinationof all possible attributes that
can uniquelyidentifythe rows /tuples in the given relation.
Super key is a superset of candidatekeys.
A table can have multiple super keys.
A SK may have additionalattributethat are not needed for
uniqueidentity .
All possible combinationsof attributes.
Candidatekey-
Candidatekey is a minimalsuperkey or a super key with no
redundantattributes.
It is called a minimal superkey because we select a candidate
key from a set of super key such that selected candidatekey
is the minimum attribute required to uniquelyidentify the
table.
Candidatekeys are defined as distinct set of attributes from
which primary key can be selected.
Candidatekeys are not allowedto have null values.
Primary key – choose a key from candidatekey
A primary key is one of the candidatekey chosen by database
designer to uniquelyidentify the tuple in the relation.
3. The value of pk can never be null
The value of pk must alwaysbe unqiue.
The values of pk can never be changed – no updationis
possible
The value of pk must be assigned when inserting a record
A relation is allowed to have one primary key.
Alternate key – out of all candidatekeys only one is selected
as pk , remaining keys are called alternate keys
Empid- primary key
Name, adharno,email id, dept id- alternate keys.
Foreign key –
A key used to link two tables together
An attribute / set of attribtes in one table that referes to pk
in another table.
The purpose – to ensure referential integrity of the data.
Foreign key references the pk of the table.
Fk can only take pk
Fk can be null.
There is no restriction that foreign key is unique.
Composite key / compound key – a key that has more than
one attribute .
Cust_id Order_id Productcode Product
4. count
CO1 001 P111 5
CO2 012 P111 8
Co3 012 P222 6
Co1 001 P333 9
{Custid, productcode}
One to many
Relational Query Language – query language is the language
in which user requests informationfrom databse.
e.g sql – structured query language
query – retrieval
2types of query languages
Procedural query language –the user instructs the system to
perform a series of operationsto produce the desired results.
User tellswhat data to be retrieved from data base and how
to retrieve.
Non prodecural query language – (declarative)
User instructs the system to produce the desired results
without telling step by step process.
User tellswhat data to be retrieved from data base but
doesn’t tell how to retrieve it .
Two pure(mathematical)query language
5. Relationalgebra – procedural query language
It is more operational
Very useful for executionalplan.
Relationalcalculus
Non procedural query language
It is non operational
Tuple relationlcalculus
Domain relationalcalculus
Relationalmodel RDBMS
RELATIONAL algebra,calculus sql
algorithm code
concept reality
theoretical practical