View on GitHub

Coding Practice

Databases

Index

Table of Contents

Important points

Database properties

Atomicity: Entire operation must be done in a single transaction. A good example is debiting money from senders account and crediting it into receiver’s account. Both should be done or not to be done. Doing only one operation is not allowed.

Consistency: If two requests are trying to get the same information, both of them should receive the same information. Simply, all users should see the value written by latest update transaction.

Isolation: Two different users operating on a particular table should be isolated. Each transaction is independent of the other.

Database types

SQL relational databases

Non relational databases

Key value stores

Document databases

Columnar databases

Data-warehouses

MongoDB

Cassandra

HBase

CAP theorem in distributed databases

Databases that offer various combinations of C,A & P

C and P

A and P

C and A

Indexing

Categories of indexing

Dense Indexing

Sparse indexing

Types of indexing

Primary

Created on the ordered primary key of a table. Use preferably Sparse indexing.

Clustered

Created on the ordered non-key field of the table. Use preferably Sparse indexing.

Secondary

Created on the unordered primary key of the table. Here only dense index is possible because the table is not ordered.

Database sharding

Horizontally partitioning the database is called sharding.

Violations and isolation levels in DBMS

Violations

Isolation levels

Isolation Level Dirty Read Nonrepeatable Read Phantom Read
Read uncommitted Possible Possible Possible
Read committed (default for Oracle) Not possible Possible Possible
Repeatable read Not possible Not possible Possible
Serializable Not possible Not possible Not possible