You are on page 1of 13

DATABASES

SRPs BOOK PDF


Databases = Collection of related data DBMS File System
DBMS : S/W used to manage Databases. The user is not required to The user has to write the procedures for
Tasks by DBMS : Data definition , Data up dation, write the procedures. managing the DB.
Data retrieval , use administration. Gives an abstract view of data Provides the detail of the data
Characteristics of DBMS : Digital repository , that hides the details. representation and storage.
security , Backup & Recovery , contains ACID Provides a crash recovery doesn't have a crash mechanism.
Properties, Provide logical view. mechanism
Abstraction = hide irrelevant details from users. provides a good protection Very difficult to protect a file under the file
mechanism. system.
There are mainly 3 levels of data abstraction:
Physical: how data is actually stored in memory. 1-Tier Architecture 2-Tier Architecture
Logical: Information that is actually stored in the • The database is directly • Same as basic client-server.
database in the form of tables. available to the user. • Applications on the client end
View: Only a part of the actual database is viewed • Any changes done here can directly communicate with
by the users. will directly be done on the database at the server side
What is File System?
SRP1 the database itself. used by ODBC, JDBC.
DBMS that allows access to single files or tables at Logical DI = Changes in 3-Tier Architecture
a time. Data is directly stored in set of files. conceptual view of data, user • Contains another layer
Flat File = When only 1 table is stored in single file view will not be affected. between the client and
SCHEMA Physical DI :Change internal server.
 Overall design of a DB = Skeleton structure schema without change the • Client can't directly
 Represents the logical view of the entire DB. conceptual schema communicate with server.
1. For Strong Entity Set With Only Simple Attributes- 1
SRP 2
2. For Strong Entity Set With Composite Attributes- 1
Minimization of ER Diagram = 3. For Strong Entity Set With Multi Valued Attributes- 2
ER Model to Relational model ?
Primary Key ? 4. Translating Relationship Set into a Table- 1
1. One to One = P.K can be of Table 5. Binary relationship with cardinality ratio m:n 3
1 or 2
2. One to Many = P.K will be of 6. Binary relationship with cardinality ratio 1:n 2
table on many side. 7. For Binary Relationship With Cardinality Ratio m:1 2
3. Many to One = P.K will be of
table on many side. 8. For Binary Relationship With Cardinality Ratio 1:1 2
4. Many to Many = Combined P.K
9. For Binary Relationship With Cardinality Constraint 2
of both table.
and Total Participation Constraint From One Side
10. For Binary Relationship With Cardinality Constraint 1
and Total Participation Constraint From Both Sides-
11. For Binary Relationship With Weak Entity Set- 2
Super key = identify each tuple uniquely + Composed attribute. 1. Integrity Constraint = Ensure insertion
Candidate Key = minimal super key + unique + not null + composite , updation & deletion that it will not
attribute + multiple C.K change.
Primary key = C.K + Only one + unique + not null + no updation 2. Domain constraint = Value of attribute
Foreign Key =An attribute ‘X’ is called as a foreign key to some other must be of same type [AGE = integer]
attribute ‘Y’ when its values are dependent on the values of attribute ‘Y’. 3. Key constraint = attribute value must
Not Necessarily unique + take null value be unique
Partial key cannot identify tuple uniquely 4. Entity integrity constraint = value
cannot be null
A Join operation combines related tuples from different relations, if and 5. Referential integrity constraints, if a
only if a given join condition is satisfied. It is denoted by ⋈. foreign key in Table 1 refers to the
TYPES : Primary Key of Table 2, then every
1. Natural Join = set of tuples of all combinations in R and S that are equal value of the Foreign Key in Table 1
on their common attribute names. must be null or be available in Table 2.

2. Outer Join (LOJ , ROJ & FOJ) = deal with missing information & return
matching items. Projection = Removes duplicate data +
LOJ = Return matching items of Left table & for non matching return NULL Display data
for right table Selection = Selects but not display
ROJ = Return matching items of Right table & for non matching return Union = Return Unique Data + Same set
NULL for Left table of attributes
FOJ = LOJ + ROJ SRP 3 Intersection = Return common data +
3. Equi Join = Based on matched data as per the equality condition Same set of attributes
Union = Combine 2 or more SELECT queries SQL Set Operation Operator Description
+ Eliminate Duplicate rows. Combine 2 or more
ALL It compares a value to all
Union All = removing duplication & sorting the data. SQL SELECT values in another value set.
Minus = No duplicates + ascending order by default statements. It allows the existence of
AND
Intersection = common rows from both the SELECT multiple conditions in an SQL
statements. ADVANTAGES statement.

ANY It compares the values in the


High Speed list according to the condition.
SQL Commands BETWEEN It is used to search for values
No Coding Needed that are within a set of values.
DDL DML DCL TCL DQL
IN It compares a value to that
Well Defined
Create Insert Grant Commit Select Standards
specified list value.

NOT It reverses the meaning of any


Drop Update Revoke Rollback Portability logical operator.
Alter Delete Save Point OR It combines multiple conditions
Interactive Language in SQL statements.
Truncate It is used to search for the
Multiple Data View EXISTS
presence of a row in a specified
table.

i.
ii.
RULES OF SQL
Not case sensitive. In general, keywords in uppercase.
Statements are dependent on text lines. We can use a single SQL
SRP 4 LIKE It compares a value to similar
values using wildcard operator.

statement on one or multiple text line. Q. WHAT IS AUTO – COMMITTED COMMANDS ?


iii. can perform most of the actions in a DB by SQL statements. Permanently save all the changes in the DB.
iv. Depends on tuple relational calculus & relational algebra. DDL  YES DML  NO
Subquery SQL Aggregate Functions
A query within another SQL
query and embedded within 1. SQL aggregation function is used to perform the calculations on multiple
the WHERE clause. rows of a single column of a table. It returns a single value.
2. It is also used to summarize the data.
• COUNT
• SUM
Indexes used to retrieve • AVG
data from the database • MAX
very fast. • MIN SRP 5
INNER JOIN selects records that have matching values in both tables as long as the condition is satisfied.
The SQL left join returns all the values from left table . If there is no matching join value, it will return NULL.
RIGHT JOIN returns all the values from the values from the rows of right table .If there is no matching , it will return NULL.
FULL JOIN = LOJ + ROJ , Join tables have all the records from both tables. It puts NULL on the place of matches not found.

SQL GROUP BY statement is used to arrange identical data into groups. Use with SELECT.
HAVING clause is used to specify a search condition for a group or an aggregate.
The ORDER BY clause sorts the result-set in ascending or descending order.
BCNF :
(NORMALIZATION) SRP 6 For each Functional Dependency X  Y
X must be a super key.
FIRST NORMAL FORM : R (A,B,C,D)
1. No Composite values A  BCD
2. Same kind & unique entries BC  AD
3. No 2 rows are identical. D  B (Not BCNF)
Key = A, BC

SECOND NORMAL FORM : 1. One C.K = 3NF & BCNF


No partial dependency 2. NO Transitive Dependency = 3NF
TRICKS
BC  ADEF 3. NO Transitive Dependency = BCNF
BF 4. Lossless decomposition – 2NF , 3NF, BCNF
Where , BC = C.K 5. No Lossy Decomposition - 2NF , 3NF, BCNF
6. Dependency Preserving - 2NF , 3NF
THIRD NORMAL FORM : 7. Not Always Dependency Preserving - BCNF
8. R with only trivial FD – BCNF
C.K = A , BC
X
NPA ------------- NPA
NPA = D , E
9. BCNF = 0 redundancy
10. If All are Prime Attributes = 2NF , 3NF
A  BCDE 11. Binary Relation = BCNF
BC  ADE 12. In Relational DB , Every Relation is in 1NF
D  E (NPA PROBLEM)
IRRECOVERABLE & RECOVERABLE Schedules T1 T2 T3
R(A) Cascading
Transaction Transaction W(A)
T1 T2 SRP 7 R(A)
R(A)
W(A) Cascadless
W(A)
R(A)
R(A) // Dirty Transaction T1 Transaction T2 T1 T2
W(A)
Read
Failure R(A)
W(A) R(A)
Commit W(A)
W(A)
Commit
R(A) // Dirty
Rollback Read R(A)
W(A)
Strict W(A)
Commit
Commit
T1 T2
Commit //
S Delayed W(A)
Commit/
C Rollback
R R(A)/W(A)
S1 S2 S3
T1 T2 T1 T2 T1 T2 T3 1. T1 T2
R(P) R(P) SRP 8 R(A)
W(Q) W(Q) NO
R(P) R(A)
R(P)
W(P) W(P) W(A)
R(Q) R(Q) W(A) T3
W(Q) W(Q)
R(Q) R(Q)
W(Q) W(Q) T1 T2 T3 2. Blind Write
R(A)
Present : W3 (A)
Conflicting Operations :
1. Different Transactions R(A) 3. T1  T3
2. Same item W(A) (T2, T3) → T1.
3. At least 1 write operation
W(A)

T1 T2 T1 T2
T1 NO T2
YES NO
VIEW T3
CONFLICT SERIALIZABLE ? SERIALIZABLE ?
S1 S2 CONFLICT
VIEW EQUIVALENT ? EQUIVALENT ?
T1 T2 T1 T2

T1 T2 T3 R(A) R(A)

Read(P)
SRP 9 W(A) W(A)
R(A) R(B)
Write(P)
W(A) W(B)
Write(P) S1 R(B) R(A)
Read(P) W(B) W(A)

Write(P)
R1(A) , W2(A) + W1(A) , R2(A) + W1(A) , W2(A)
T1 T2 T3 T1 T2 T1 T2
Read(P) R(X) R(X)
Let X = 2 and Y = 5.
Write(P) X=X+5 X=X+5

Read(P) S2 W(X) W(X) Results by Schedule S1- X = 21


Write(P) R(Y) R(X) and Y = 10
Results by Schedule S2- X = 21
Write(P) Y=Y+5 X = X x3
and Y = 10
W(Y) W(X)

1. Initial Readers same R(X) R(Y)


2. Write – Read Sequence must be same X=Xx3 Y =Y+5 RESULT
3. Final writers are same EQUIVALENT ?
W(X) W(Y)
Concurrency control problems Lock-Based Protocol
1. Dirty read problem = Reading from In this type of protocol, any transaction cannot read or
uncommitted transaction write data until it acquires an appropriate lock on it.
2. Lost Update Problem = Data loss , W/W Conflict Shared Lock = Read Lock
3. Unrepeatable Read problem = T different value Exclusive lock = Read/Write lock
of X in its second reading. SRP 10
4. Phantom Read problem = T finds that there does There are two phases of 2PL:
not exist any variable X when it tries reading X Growing phase: new lock on the data item may be acquired
again. by the transaction, but none can be released.
Shrinking phase: existing lock held by the transaction may
Concurrency Control Protocol be released, but no new locks can be acquired.
Concurrency control protocols ensure atomicity,
• The only difference between 2PL and strict 2PL is that
isolation, and serializability of concurrent
Strict-2PL does not release a lock after using it.
transactions.
• 2 PL – Cascading abort
Advantages and Disadvantages of TO protocol: The Timestamp Ordering Protocol is used to order the
• TO protocol ensures serializability. transactions based on their Timestamps.
• TS protocol ensures Deadlock free The priority of the older transaction is higher that's why it
• May not = Recoverable and Cascad free executes first.

Wait_Die : An older transaction is allowed to wait for a younger transaction, whereas Concurrency
a younger transaction requesting an item held by an older transaction is aborted and Control
restarted. [OPPOSITE IN WOUNDED WAIT]
SRP 11
SRP 12

Copy protected with Online-PDF-No-Copy.com

You might also like