You are on page 1of 13

Data independence

1. Physical - It allows us to focus on providing a logical database description


without worrying about the physical structure
2. Logical - It allows us to change the middle level of DBMS, the logical
schema level, without changing the external views. Eg. If a table is split
into 2, the view must show the joint table to user.
3. View - The view level of abstraction exists to simplify their interaction with
the system. Many users of the database system do not need all this
information; instead, they need to access only a part of the database.

Data Model
• A collection of conceptual tools for describing data, data relationships,
data semantics, and consistency constraints.
• Four different categories
o Relational model
o Entity – relational model
o Semi structured data model like JSON
o Object based Data model – C++

Codd’s Rules
1. The information in a relational database must be stored in columns or
rows of a table, i.e., a cell.
2. Each and every datum in a relational database must be logically accessible
using the combination of the table name, primary key value, and column
name.
3. NULL values are fully supported in a relational database and represent
missing information or inapplicable information in a systematic way,
independent of the data type. NULL values are different from empty
strings, blank spaces, and 0
4. Database Description (Catalog) of a complete database must be stored
online. The rules of the rest of the database must also apply to the
Catalog. The query language used to query the database should be used
for the catalog also.
5. Relational systems can support multiple languages and different modes
of using terminals, such as fill-in-the-blanks mode. However, there must
be at least one language whose statements are expressible according to a
well-defined syntax.
6. Theoretically, updatable views are also practically updatable by the
database system.
7. The database system must follow high-level relational operations such as
insertion, updation, and deletion at each level or row by row. It also
supports the union, intersection, and subtraction operations in database
systems.
8. The working of a database system should be independent of the physical
storage of its data. If a file is modified (renamed or moved to another
location), it should not interfere with the working of the system.
9. If there is a change in the logical structure (table structure) of the
database, the user view of the data must not change. Say a table is
partitioned into two tables, the new view should give the result as the join
of the two tables.
10.Integrity constraints specific to a particular relational database must be
defined in the relational data sub-language and stored in the catalog and
not in the application.
11.A database should work properly regardless of its distribution across a
network. The end-user should not be able to see that the data is
distributed over many locations, they should always get the impression
that the data is located at a single site only.
12.If a relational system allows low-level access, that low cannot be used to
bypass the integrity rules to modify the data. This can be achieved with
some sort of looking or encryption.
DBMS Architecture
Components of ER Model

1. Entity set
a. Tangible – that exist physically eg. Person
b. Intangible – that does not exit physically – eg. Account
c. Strong – does not depend on others
d. Weak – depend on strong entity for existence
2. Attribute
a. Simple – cannot be broken eg. age
b. Composite – can be broken eg. Address
c. Single valued
d. Multi valued – eg: many phone numbers
e. Derived – that can derived from another eg. Age from DOB
f. Null valued
3. Relationship
a. Unary – related to another entity of same type
b. Binary – two related to each other
c. N-ary – N related to each other via single relation
4. Cardinality – no of instances that can be related to other
a. One to one – eg. 1 person has 1 Uid and 1 Uid is given to 1 person
b. One to many – eg. 1 person has many order but 1 order
correspond to 1 customer
c. Many to many – eg. 1 student enrol in many course, 1 course
taken up by many students
5. Participation of entity
a. Total – repr by double line eg. Each student must take atleast 1
course
b. Partial – repr by single line to diamond eg. A course can have no
Students

Extended ER Model
1. Generalization – repr by a triangle(is a) eg. Car, truck, bike can be
generalized into superclass Vehicle
2. Specialization – eg. Reverse of above
3. Aggregation – 2 entity treated as 1 entity , enclosed in a box eg.
Employee works on project and manager manages both

Cardinality
-> one to one

-> one to many (mandatory)

-> many to one (optional)

DDL Commands
• Data Definition language
1. Create -> create table - (-,-)
2. Truncate -> truncate table -
3. Drop -> drop table -
4. Alter -> alter table - add - / drop column - / rename column - to - /modify
column - -
5. Rename -> rename - to -
DDL Constraint
1. Primary key -> unique and not null
2. Foreign key -> This constraint creates a relationship between two tables
and ensures that the values in one table match those in another. It is used
to prevent deletion or modification of data that would break the
relationship.
3. Unique
4. Not null
5. Check
6. Default

DML Commands
• Data Manipulation Commands
1. Select -> select - as - from - where -
2. Insert -> insert into - (-) values (-)
3. Update -> update - set - where -
4. Delete -> delete from - where –
• Order -> order by -,-,- asc/desc
• Group -> group by - having -

DCL Commands
• Data Control Commands
1. Grant -> grant select/insert/all on - to -
2. Revoke -> revoke select/insert/all on - to -

TCL Commands
• Transaction Control Commands
1. Commit
2. Rollback -> rollback/rollback to -
3. Savepoint -> savepoint -
Set operations
1. Union
2. Intersect
3. Minus

Aggregate functions
1. Min
2. Max
3. Count
4. Sum
5. Avg
6. Stddev

Joins
1. Cross join -> select - from A cross join B
2. Equi join -> select - from A cross join B where A.roll = B.roll
3. Left outer join -> select - from A left outer join B where A.roll = B.roll
4. Right outer join -> select - from A right outer join B where A.roll = B.roll
5. Full outer join -> select - from A full outer join B where A.roll = B.roll

Views
• Create view - as select - from - where -
Trigger
Create trigger trigger_name
after/before insert/update/delete
on table_name for each row
begin
-----
End

Armstrong axioms for functional dependencies


1. Reflexive -> X ⊇ Y then X → Y
2. Augmentation -> X → Y then XZ → YZ
3. Transitive -> X → Y and Y → Z then X → Z
4. Union -> X → Y and X → Z then X → YZ
5. Decomposition -> X → YZ then X → Y and X → Z
6. Pseudo transitive -> X → Y and YZ → W then XZ → W

Normalization
• Normalization is a process of decomposing the relations into relations
with fewer attributes.
• The normal form is used to reduce redundancy from the database table.
• Normalization is the process of organizing the data in the database.
• Candidate key -> minimal key that is required to reach all attributes for
a given relation.
• Super key -> all keys that can reach all attributes for a given relation
• Prime attribute -> attributes that make up the candidate key
• Non prime attribute -> attributes that are not present in any candidate
key
Normalization anomalies
1. Updation -> The update anomaly is when an update of a single data value
requires multiple rows of data to be updated. if we want to update the
address of Ramesh then we will have to update all the rows where
Ramesh is present. If during the update we miss any single row, then there
will be two addresses of Ramesh, which will lead to inconsistent and
wrong databases.
2. Insertion -> Insertion Anomaly refers to when one cannot insert a new
tuple into a relationship due to lack of data. If we create a new row of a
worker, and if it is not allocated to any department then we cannot insert
it in the table so, it will create an insertion anomaly.
3. Deletion -> The delete anomaly refers to the situation where the deletion
of data results in the unintended loss of some other important data. If we
want to delete the department number ECT669 then the details of Rajesh
will also be deleted since Rajesh's details are dependent on the row of
ECT669.

Normal forms
1. 1NF -> A relation will be 1NF if it contains an atomic value.
2. 2NF -> all non-key attributes are fully functional dependent on the entire
primary key. If AB → C then decompose in A → B and AB
LHS should be a subset of candidate key & RHS should be a non prime
attribute
3. 3NF -> there is no transitive dependency for non-prime attributes. If
A → B → C in same table, then decompose into A → B and B → C
LHS should be a super key or RHS should be prime attribute
4. BCNF -> LHS must be a super key. If AB → CDE then decompose into
A → C and B → DE and AB tables
Transaction
• A set of instructions required to complete simple logical unit of work
1. Atomicity -> the transaction should be completed 0% or 100%
2. Consistency -> the data much be consistence before and after the
transaction gets completed
3. Isolation -> every user must be isolated from each other
4. Durability -> the data must persist after the transaction is completed,
even if the system fails

Flowchart

Schedule
• A sequence of instructions that specify the chronological order in which
instructions of concurrent transactions are executed
1. Serial schedule -> no transaction starts until a running transaction has
ended
2. Concurrent schedule -> a transaction can start execution even if running
transaction hasn’t stopped
Conflict serializable

View serializable
1. First read must be done by same transaction
2. Last write must be done by same transaction
3. Intermediate reads after writes must be by same transactions
Query processing
• Activities involved in extracting data from a database.
• Cost -> total elapsed time for answering query
o Disk access cost
o Cpu cost
o Network communication cost

Evaluation of expressions
1. Materialization
a. Evaluate one operation at a time from inner to outer
b. Writes the intermediate results to disk
2. Pipelining
a. Evaluate several operations at a time
b. Pass results from one operation to another instead of storing

Select operator
• Symbol -> σ
• Commutative -> σA(σB(customer)) = σB(σA(customer))
Project operator
• Symbol -> π
• πA(πB(πC(customer))) = πA(customer)

Join operator

You might also like