Friday, May 1, 2009

Integrity & Security, Normalization, Transaction Management and Concurrent Execution

Constraint can be at column level, table level and even at database level. Examples of column level are not null, check constraint, foreign keys. Example of table level constraint is primary key.
Triggers:
Authorization in SQL:
GRANT ONTO
user list may be a user-id or public-which allows all valid users the privilege granted.
Granting a privilege on a view does not imply granting any privilege on the underlying relations.
Privileges in SQL are the following: select, update, delete, references, usage, all privileges.
REVOKE ONFROM[restrictcascade]
REVOKE SELECT ON branch FROM u1,u2,u3 cascade;
Revocation of a privileges from a user may cause other users also to lose that privilege. This is called cascading of revoke. With restrict REVOKE command fails if cascading revokes are required.
Normalization:
key idea is to reduce the level of redundancy of data, since there are chances to have the multiple version of same data. There is method of quantifying 'how normalized a database is'- Normal Forms(NF).
Any increase in normalization generally involves splitting existing tables into multiple new table, which must be rejoined at the time of query. This can sometime leads to performance issues. So, intentional denormalization is used in some application. Note that these are not the improvements in the relational model, rather they borrow aspects of navigational database and hierarchical database that are speedier than their relational counterparts.
First Normal Form(1NF): A database is said to have in 1NF if no record(row) is repetitive, no field is blank and there is no multiple data in one field.
Second Normal Form(2NF): A database is said to have in 2NF if it is in 1NF and every non key attribute is dependent on primary key. If any column does not dependence on primary key, it should not in that table, rather new table may contain it.
Third Normal Form(3NF): A database is said to have in 3NF if and only if it is in 2NF and transitive dependency is removed.
3NF is widely considered to be sufficient for many application. Most tables reaching 3NF also reaches BCNF.
Steps to perform normalization:
1. Eliminate repeating groups
2. Eliminate redundant data
3. Eliminate columns not dependent on key
4. Isolate independent multiple relationships.

Transaction Management:
TM begins with BEGIN and ends with SQL COMMIT. ROLLBACK is used to rollback to previous consistent state.
Transaction State-
Active- transaction is being executed.
Partially Committed- after the final statement is executed.
Failed- normal execution can no longer proceed.
Aborted-Transaction is stopped and database is being restored to previous consistent state.
Committed- after successful completion.
Recovering from crash:
Steps- Analysis, Redo and Undo(working backwards in the log)

Concurrent Execution:
Problems in concurrent execution
1. Lost Update Problem
2. Temporary Update(or dirty read) Problem
3. Incorrect summary problem
In the precedence graph of any schedule has a cycle then the schedule is not conflict serializable. If it is acyclic then we declare that the schedule is conflict serializable.

No comments: