MCSE Training Guide (70-229). Designing and Implementing Databases with MicrosoftR SQL ServerT 2000 Enterprise Edition
ER Modeling
Data modeling concepts are the basis for everything we do in the industry as DBAs. As seen in Chapter 2, an ER data model consists of three main components that are present in any model format:
Primary Keys
Primary keys consist of sets of attributes whose values uniquely identify the rows in a entity. Primary keys give an ID to a row and make the row unique throughout the entity. This means that rows can be located easily by this identifier. Additionally, primary keys can be made up of multiple columns known as a composite key. Foreign Keys
Foreign keys help in the relational process between two entities. When a primary key is created on a parent entity, it can be connected to the foreign key of another entity. You can also link two entities by relating a foreign key to a unique column not defined as the primary key. One-To-One Relationship
This type of relationship occurs when one row or data element of an entity is associated with only one row or element in the second entity. It is not surprising that one-to-one relationships are uncommon in the real world. They are used mostly when an entity has an extraordinarily large number of attributes ”then the entity is split in two to make it easier to manage. An extra entity also might be desired when developing the physical storage locations of the data. By separating seldom-used data from more frequently used information, faster data retrieval and updates can be accommodated. One-To-Many Relationship
One-to-many relationships exist when a single instance of an entity (the parent entity) relates to many instances of another entity (the child entity). One-to-many relationships are the most common type of relationship. It is a natural occurrence in the real world ”for example, a customer will have many orders, and a manufactured product will have many components. Many-to-Many Relationship
This type of relationship occurs when many rows or data elements in an entity are associated with many rows or data elements in another entity. For example, a many-to-many relationship occurs between the Trainee and Course entities. Many Trainees can enroll to a single course, and one trainee can be enrolled into numerous courses. This type of relationship is not uncommon in the real world. However, SQL Server doesn't actually directly implement many-to-many relationships. A many-to-many relationship is implemented using three entities. The two main entities are connected together using a third entity. The third entity contains keys and interrelationship information. Each entity is connected to the new entity as a one-to-many relationship. To discover the cardinality of a relationship, you look at the correlation between the entities. Entity Integrity
Entity integrity defines a unique row attribute as an identifier for individual entities. Generally, the regulations of this type of data integrity are easy to follow. Simple ways of enforcing this type of integrity are using primary keys, UNIQUE constraints, and unique indexes when the entity design moves into the physical stage of design. Entity integrity specifies that primary keys on every instance of an entity must be present, unique, and have values other than null content. Domain Integrity
Domain integrity is restricting the data entered to a domain or range of values, and thus preventing incorrect data from entering the system. Referential Integrity
Referential integrity specifies that every foreign key value map to a primary key or other unique value in related tables. Referential integrity guarantees the smooth navigation of moving from entity to entity, so it is extremely important to ensure proper referential integrity definition. Referential integrity ensures that no orphaned records exist. Orphaned data is a term used when data in a child entity exists that points to a non-existent parent. Advanced Referential Integrity Options
When defining relationships to be used in a SQL Server database system, two new options exist that allow more control over the actions that can occur affecting key values. Cascade Update Related Fields and Cascade Delete Related Records allows updates or deletions of key values to cascade through the tables defined to have foreign key relationships that can be traced back to the table on which the modification is made. A cascading deletion will occur when you delete a row with a key referenced by foreign keys in existing rows in other tables; all rows containing those foreign keys are also deleted. A cascading update occurs when you update a key value in a row where the key value is referenced by foreign keys in existing rows in other tables. All foreign key values are also updated to the new value specified for the key. SQL Server Data Types
The following list (excerpted from Chapter 2) details SQL Server data types:
|