Database Notes --- Chapter 1

What is database?
-> Interrelated data
What is DBMS?
-> System to access that data and visulalize it and update it efficiently
Advantages of DBMS over File Systems
-> 1) Data Inconsistency/Redunduncy
2) Data Isolation (Much like Java's Platform Independence)
3) Data Integrity (Data correctness checking conditions)
4) Atomicity of operations(Consider Bank Transfer note that debit and credit
is considered to be atomic operation)
5) Concurrency (At a time concurrent queries to database)
6) Security (Access management)
Database Notes --- Chapter 2
>>>>Relational Database Management Systems (RDBMS)
>>>>Structured Query Language(SQL)
>>>>Relational Data Model (RDM)
What are attributes?
->Attributes are the particular columns in the database tables such as in the fo
lowing table street and name are some of the attributes
|Street| Name | Phone|
|1st | Yati | 78912|
|2nd | katr | 72982|
What are the characteristics of attributes?
-> Name,Domain and Atomic nature of attributes.
Name is kind of identifier for attributes.Domain is the set of values of any sam
e type that name can be.Attributes usually are atomic i.e they can not be broken
further into any subparts."null" is special value that domain always consists o
What are relation Schema ?
->Relation schema is the set of attributes which can contribute to the formation
of n-ary tuples in any relation(to be defined later) or relation instance(to be
defined later) consists of.
Note -- It is a set.
for e.g.
>> {Street,Name,Phone}
>>>>Schema means description.
for e.g.
>> Address schema
What is notation for Relation Schema?
->It is denoted in capital letter.
for e.g.
>> R

If there are more than one candidate keys.Chapter 3 -------------------------------------------------------------------------------- ----------------------------- It is procedural language with six operations/operations that operate on relatio ns allowded >>>>Relational Algebra>>>> >> Operators >> 1) Select : sigma sign 2) Project : pi sign 3) Union : Capital U sign 4) Set Difference : minus sign 5) Cartesian Product : cross sign 6) Rename : rho sign >> Propositional Calculas of expressions >> 1) and 2) or 3) not >> attribute comparator >> 1) > . In simpler words. What is database ? A precise definition ---.It consists of all the possible pairs What is relation instance? ->Relation instance is the specific instance as function is that of relation in mathematics.It consists of tuple and table denotes relation instance denoted by small letters like r.The relation of first table is called refernced relatio n and second table's relation is called as referencing relation. >> Name can never be superkey as it is What is candidate key? ->Minimal subset of superkey is candidate key which also uniquely determines any tuple in any relation of any relation schema. 2) Secondary Keys --> All candidate keys other than chosen primary key are called secondary keys.This gives rise to concept known as candidate key. -------------------------------------------------------------------------------- ----------------------------- Database Notes -. a foreign key is a field (or collection of f ields) in one table that uniquely identifies a row of another table. Note -.And anything appended to any superkey is also superkey. for e.What is relation? ->Relation is the cross product of the domain of attributes in the order of any permutation of any number of elements of relation schema and it is denoted as r( R) Note--.Databse consists of relations and multiple inter-relat ed relations. but it refers to the primar y key in the first table.g.And each tuple is denotes a row. What are foreign keys? In context of relational databases. the foreign key is defined in a second table.they are divided into two types -----> 1) Primary key --> This is the choice of database designer to be chosen as candidate key. What is superkey? A superkey is subset of relation schema which can uniquely determine any tuple i n any relation.

.(r)} = { t|t belongs to r and p(t) } > It selects the tuples from relation instance for which the predicate is true.Chapter 5 -------------------------------------------------------------------------------- --------------------- >>Additional Operators >>These are like serived operators and they do not add an y power but simplifies the query 1) Set Intersection 2) Join 3) Division 4) Assignment 1) Set Intersection ------------ r intersection s = {t|t belongs to r and t belongs to s} In intersection both should have same schema and does not changes schema 2) Join -------------------- 1) Equality join --- r |><|(=) s = sigma{=.A3..CA=s...A2.Both r and s should have same schema to work this one out...An.s = {t|t belongs to r and t does not belongs to s} Note -.......An) and t1=(A1.CA. It removes duplicates. 2) Project ---- pi{A1.2) < 3) >= 4) <= 5) = >>Operator Details>> 1) Select ---- sigma{p. And this is how rename operation works. 6) Rename Operation rho{S...(r X s)} 2) Natural join --- r * s = sigma{r. x = {t|t=(A1.(r)} ---.... -------------------------------------------------------------------------------- --------------------- Database Notes -..s) and for every u belonging to s tu belongs ..Where S is mapping function for attributes such that S(r) = s . 5) Cartesian Product ---- r X s --.. 3) Union ---- r U s = {t|t belongs to r or t belongs to s} Note -.An.Both r and s should have same schema for this to work out 4) Set Difference ---- r ....... > It does not changes the schema.A2.P redicate is written in form of epression of attributes/constants joined with pro positional calculas of expressions..A2.....(r)} = x where..It changes the schema and same way it is done as cartesian product o f two sets.. Note --.(r X s)} where CA is common attribute >>Equality join does not changes schema from that of r X s while Natural join does change schema as there is only one copy of CA from that of r X s 3) Division ------------------------ In the division operator---- r division s = {t|t belongs to (r .) and t1 be longs to r} It changes the schema as it gives new relation..Rename does changes the schema but not the meaning behind it.We get a new relation schema and hence just changed corresponding relation s...

(r)})} 3)Outer Join It is of three types --- 1) Left outer Join 2) Right outer Join 2) Full outer Join ------------------------- 1) Left outer Join ---- It is same as join and all left tuples need to be added too which does not follo w condition of join and missing elements are added values as null.F2... to r} for e.Fk..(sigma{partition logic.(r)} where Fi is the artihmetic operation which takes attributes as a parameter 2)Aggregation > It actually an generalized operator G which partitions given tuples of r into some partitions and it applies then generalized projection so the format of aggr egation is (partitions)G(r) = pi{F1.. .Increases power of Relational Algebra --.....Chapter 6 -------------------------------------------------------------------------------- ------------------------------------- Extended Relational Algebra --....Fk...F2. -B-|-C- 3 2 1 2 1 3 2 2 2 2 4 2 1 4 2 3 5 1 6 5 2 1 5 2 2 9 2 2 then r division s is r division s ------A------ 3 5 4) Assignment ------------------------------------ Much like the renaming operator -------------------------------------------------------------------------------- ------------------------------------- Database Notes --.Have a dditional Operations >>>>>>>>>>>>>>>>>>> Additional Operators 1) Generalized Projection 2) Aggregation 3) Outer Join 1)Generalized Projection > It allows "Arithmetic Operations" on Projection pi{F1. 2) Right outer Join It is same as Join and all right tuples need to be added too which does not foll ow conditions of join and missing elements are added values as null. 3) Full outer Join It consists of both left and right tuples with added null values for missing ele ments.g >> r s -A-|-B-|-C.

> null = null evealuates to true > Arithmetic operations follow the logic given above. <*****> Ways to handle <*****> 1) We can might reject the request 2) Or we can add new primary key ----.false and null as three values in three va lued logic. If we added new foreign key which does not refer any primary key.Powerful but not sufficient for some cases 2) There is no recursive closure .E) >>> Problems with deletion > It can violate referntial integrity That is if we deleted primary key which is referenced by foreign key is deleted then that foreign key gets orphan.Chapter 07 -------------------------------------------------------------------------------- ---------------------------------------- There are three types of database operations > Deletion >> r <.Never used >It can violate Domain Constraint Added value out of the defined bounds. >Insertion >> r <.(r U E) >>> Problems with insertion > It can violate "Referencial Integrity" <*****> Ways to handle <*****> 1) We might reject the request 2) We can either extend the request to foreign key in two ways i) We can either delete entire tuple's containing foreign keys ii) Or we can add null in place of foreign keys in child table.The word join usually means natural outer join. > Any comparison with null gives rise to null. <*****> Ways to handle <*****> 1) Reject the request 2) Expand Domain to incooperate changes > It can violate "key constraint" Added new primary key which is not primary key at all <*****> Ways to handle <*****> 1) Reject the request > It can violate "entity integrity" Primary key is set as null and insertion is done to it.Not viable/good . <*****> Ways to handle <*****> 1) Reject the request Drwabacks with relational database 1) It is first order logic. > Three valued logic consists of true. > null can also be called as unknown >> OR Logic >> > (u OR true) evaluates to true > (u OR false) evaluates to unknown > (u OR u) evaluates to unknown >> AND Logic >> > (u AND true) evaluates to unknown > (u AND false) evaluates to false > (u AND u) evaluates to unknown >> NOT Logic >> > (NOT u) evaluates to unknown -------------------------------------------------------------------------------- ---------------------------------------- Database Notes -.(r .

-------------------------------------------------------------------------------- -------------------------- Database notes -.Chapter 08 -------------------------------------------------------------------------------- -------------------------- >>>>>> SQL (Structured Query Language) >>>>>> .