You see things; and you say 'Why?' But I dream things that never were; and I say 'Why not?'

Monday, November 17, 2008

SQL Server

1) Data Integrity: The concept of applying business rules on database tables is called as data integrity.

1. There are two types of integrity, Pre- Defined and user defined

a. The predefined integrity is of three types

b. It can be implemented with the help of constraints we have three subtypes under predefined data integrity

i. Entity integrity – entity means row and entity set means table, Primary key and unique.

ii. Domain Integrity- domain means list of possible values in a column, not null, Default and check.

iii. Reference integrity-maintaining relationships, foreign key.

2) Primary key – It is collection of one or more column used to identify a row or entity, it doesn’t allow duplicates and null values and it can be simple or composite. A table can have only one Primary key.

3) Unique Key –It can be defined on single column or combination of multiple columns, it is also used to identify a row, a table can have any number of unique constraints. Unique constraint column does not allow duplicates but it do accepts one null value.

4) Not Null-In order to restrict entering null values in a column which means one must assign a value to not null column. It can be combined with other constraints also.

5) Default-Which means if a value is not inserted in a particular column, default value is assigned automatically.

6)Check-This constraint is used to check the user defined condition.

7)Foreign Key-It is a column referencing values from other table primary key column, It is used to maintain the relationships among the tables. It allows duplicates and null values by default. A table can have 253 foreign keys, foreign key column name recommended to be same as primary key column but datatype should be same.

8) Relationships- The association or dependency among the tables is called relationships, There are three types of relationships.

(i) One to many relationships, Ex -Dept to Employees. A row in one table is associated with many rows in another table.

(ii)One to One relationship,Ex-Employee to phone, A row in one table is associated with only one row in a table.

(iii)Many to Many Relationship, Ex-Many rows in one table is associated with many row in another table, it will be established using a linking table and linking table contains multiple foreign keys and composite primary key.

9) Normalization: The process of applying normal forms sequentially on the database design can be called as normalization. There are 7 types of normal form.

a) First Normal Form – A table in first normal form should follow the rule – No Multi value columns in the table.

b) Second Normal Form – A table in second normal form, it should follow first normal form and every non key column should depend on complete primary key (No Partial dependency-a non key column depends on part of the primary key is called partial dependency)

c)Third Normal Form – It should follow second normal form, No transitive dependency meaning one non key column depends on other non key column in the same table can be called as transitive dependency.

d) BCNF –It should follow 3rd normal form, no overlap between candidate keys.

10) Advantages of Normalization-

1) Normalization eliminates the redundancy.

2) It eliminates the functional dependency problems like partial dependency, transitive dependency etc.

3) Faster index creation.

4) Normalization improves the performance while performing insertions, deletions and updating into the table.

11) Drawbacks of Normalization-It degrades the performance while retrieving data from multiple tables.

12) De normalization- The reverse process of normalization is called as de normalization, This is recommended as it increases performance while retrieving data from a large table. The drawbacks of de normalization is that it introduces data redundancy , functional dependency.

OLTP – Used for daily transactions – It’s a normalized DB tables-Production servers

OLAP-De Normalized tables –Querying, analysis and reporting purpose or business intelligence purpose.

13) Candidate key – It’s a collection of one or more columns used to identify a row, a table can have multiple candidate keys. While designing tables we should make note of the following – Identify candidate keys-Define primary keys-Define unique constraints. One of the candidate key is defined as primary key and other candidate keys defined with unique constraints.

-----

What is Normalization?

Normalization is the process of efficiently organizing data in a database. There are two goals of the normalization process: eliminating redundant data (for example, storing the same data in more than one table) and ensuring data dependencies make sense (only storing related data in a table). Both of these are worthy goals as they reduce the amount of space a database consumes and ensure that data is logically stored.

The Normal Forms

First Normal Form or 1NF) through five (fifth normal form or 5NF). In practical applications, you'll often see 1NF, 2NF, and 3NF along with the occasional 4NF. Fifth normal form is very rarely seen and won't be discussed in this article.

First Normal Form (1NF)

First normal form (1NF) sets the very basic rules for an organized database:
  • Eliminate duplicative columns from the same table.
  • Create separate tables for each group of related data and identify each row with a unique column or set of columns (the primary key).

Second Normal Form (2NF)

Second normal form (2NF) further addresses the concept of removing duplicative data:
  • 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.

Third Normal Form (3NF)

Third normal form (3NF) goes one large step further:
  • Meet all the requirements of the second normal form.
  • Remove columns that are not dependent upon the primary key.

Fourth Normal Form (4NF)

Finally, fourth normal form (4NF) has one additional requirement:
  • Meet all the requirements of the third normal form.
  • A relation is in 4NF if it has no multi-valued dependencies.

No comments:

Followers