ACID Properties

ACID Property is the most important part of the database. ACID stands for Atomicity Consistency Isolation Durability.

Atomicity:  This means that “all or nothing”. When an update occurs to a database either all or none of the update will become available to anyone beyond the user. This update to the database is called a transaction and it either commits or aborts.

Consistency:  It ensures that any changes to values in an instance are consistent with changes to other values in the same instance.

Isolation:  Isolation is is needed when there are concurrent transactions. Concurrent transactions are transactions that occur at the same time, such as shared multiple users accessing shared objects.

An important concept to understanding isolation through transactions is serializability. Transactions are serializable when the effect on the database is the same whether the transactions are executed in serial order or in an interleaved fashion.

Durability: Maintaining updates of committed transactions is important. These updates must never be lost. The ACID property of durability addresses this need. Durability refers to the ability of the system to recover committed transaction updates if either the system or the storage media fails.

We have the perfect professional SQL Training Course for you!

  • Normalization:

Normalization is a technique which is used to organize the data in the database. It is a systematic approach to remove the data redundancy. Normalization is mainly used for two purpose,

  • To remove data redundancy.
  • Ensuring data dependencies is proper.

Without normalization 3 anomalies occurred and it becomes difficult to handle and update data. To understand these anomalies let’s take an Student table

IDNameAddressSubject
201AkshayJaipurMaths
202CharuBombayBio
203DishaBanglorePhysics
204EvaNoidaMaths

 

  • Updation Anamoly – To update address of a student who occurs twice or more than twice in a table, we will have to updateAddress column in all the rows, else data will become inconsistent.
  • Insertion Anamoly – Suppose for a new admission, we have a Student id, name and address of a student but if student has not opted for any subject yet then we have to insertNULL there, leading to Insertion Anamoly.
  • Deletion Anamoly – If id 401 has only one subject and temporarily he drops it, when we delete that row, entire student record will be deleted along with i
  • Normalization Form:

Normalization Rules are divided into 4 normal forms.

  • First Normal Form
  • Second Normal Form
  • Third Normal Form
  • BCNF

First Normal Form:

As per First Normal Form, no two rows of data must contain repeating data i.e., whenever we search for a particular result the multiple columns cannot be used to fetch the same row.

Each table should be organized into rows, and each row should have a primary key that distinguishes it as unique.

For example, consider a table not in first normal form

StudentAge Subject
Akshay15Maths, Physics
Charu14Biology
Disha17Maths

Student table in 1NF will be:

StudentAge Subject
Akshay15Maths
Akshay15Physics
Charu14Biology
Disha17Maths

Using the First Normal Form, data redundancy increases, as there will be many columns with same data in multiple rows but each row as a whole will be unique.

Wish to get certified in SQL! Learn SQL from top SQL experts and excel in your career with intellipaat’s SQL certification.

Second Normal Form:

As per the Second Normal Form there must not be any partial dependency of any column on primary key. It means that for a table that has concatenated primary key, each column in the table that is not part of the primary key must depend upon the entire concatenated key for its existence.

  • Meet all the requirements of the first normal form.
  • Remove subsets of data that apply to multiple rows of a table and place them in separate tables.
  • Create relationships between these new tables and their predecessors through the use of foreign keys.

For example:

New student table following 2NF will be:

StudentAge
Akshay15
Charu14
Disha17

In Student Table the candidate key will be Student column, because all other column i.e Age is dependent on it.

StudentSubject
AkshayMaths
AkshayPhysics
CharuBiology
DishaMaths

In Subject Table the candidate key will be {Student, Subject} column. Now, both the above tables qualifies for Second Normal Form and will never suffer from Update Anomalies.

Prepare yourself for the industry by going through this Top SQL Interview Questions and Answers!

Third Normal Form:

  • A relation is in third normal form (3NF) if it is in second normal form and it contains no transitive dependencies.
  • Consider relation R containing attributes A, B and C. R(A, B, C)
  • If A → B and B → C then A → C
  • Transitive Dependency: Three attributes with the above dependencies.

For example:
Student_details table

ID Name Subject DOB AddressMobile No.City

New Student_detail table:

ID NameSubject

 
Address Table:

IDAddressDOBMobile No.City

The advantage of removing transtive dependency is,

  • Amount of data duplication is reduced.
  • Data integrity achieved.

Come to Intellipaat’s SQL Community if you have more queries on SQL!

Boyce and Codd Normal Form (BCNF):

This is a higher version of third normal form. This form deals with certain type of anamoly that is not handled by 3NF. A 3NF table which does not have multiple overlapping candidate keys is said to be in BCNF. For a table to be in BCNF, following conditions must be satisfied:

  • R must be in 3rd Normal Form
  • and, for each functional dependency ( X -> Y ), X should be a super Key.

Leave a Reply

Your email address will not be published. Required fields are marked *