SQL Transaction and Indexes


A transaction is a sequence of operations performed as a single logical unit of work. A logical unit of work must exhibit four properties, called the ACID (Atomicity, Consistency, Isolation, and Durability) properties, to qualify as a transaction:

Atomicity: A transaction must be an atomic unit of work; either all of its data modifications are performed or none of them is performed.

Consistency: When completed, a transaction must leave all data in a consistent state. In a relational database, all rules must be applied to the transaction's modifications to maintain all data integrity. All internal data structures, such as B-tree indexes or doubly-linked lists, must be correct at the end of the transaction.

Isolation: Modifications made by concurrent transactions must be isolated from the modifications made by any other concurrent transactions. A transaction either sees data in the state it was in before another concurrent transaction modified it, or it sees the data after the second transaction has completed, but it does not see an intermediate state. This is referred to as serializability because it results in the ability to reload the starting data and replay a series of transactions to end up with the data in the same state it was in after the original transactions were performed.

Durability: After a transaction has completed, its effects are permanently in place in the system. The modifications persist even in the event of a system failure.

There are 2 SQL Transaction Statements:
The COMMIT Statement terminates the current transaction and makes all changes under the transaction persistent. That is all changes are recorded together in the database.
The ROLLBACK Statement terminates the current transaction and reversing all changes made under the transaction. That is if anything goes wrong with any of the grouped statements, all changes need to be aborted. The process of reversing changes is called rollback in SQL Server terminology.

SQL INDEX:
Indexes in database are used as indexes used in books, purpose of both are same. In a book we try to find out immediate Chapter with the help of Index without turning all the pages, same as in SQL Server Database if we try to find out the data from the table without scanning entire tables we use Index.An index in a database is a list of values
in a table with the storage locations of rows in the table that contain each value. Indexes can be created on either a single column or a combination of columns in a table and are implemented in the form of B-trees.
There are two types of Indexes:
Clustered:  A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages. A table can have only one Clustered Index. Clustered index will be created by default when u create primary key on a column. So we can create one clustered index per table. Clustered index is stored in serial passion

Non Clustered: A Non clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. A table can have 249 Non Clustered Index. On clustered index will be created automatically when u create unique key on a column. A table can have no. of unique keys, so we can create no. of non clustered indexes per table.

Comments