Sei sulla pagina 1di 14

Module 4

Relationships
Module 4 Overview

• Introduction to Relationships
• Planning Referential Integrity
Lesson 1: Introduction to Relationships

• Referential Integrity
• One-to-Many Relationships
• Optional and Required Relationships
• One-to-One Relationships
• Many-to-Many Relationships
• Super-Types and Sub-Types
• Self-Referencing Relationships
Referential Integrity

• Maintaining referential integrity ensures that


data remains meaningful
• In SQL Server, you can enforce referential
integrity by using:
• Foreign key constraints
• Triggers
One-to-Many Relationships
Optional and Required Relationships
One-to-One Relationships

• In a one-to-one relationship, every value in the


primary key column has a single matching value
in the foreign key column
• If a one-to-one relationship is mandatory, you
can create the foreign key in either table
• If the relationship is optional, you should create
the foreign key in the side of the relationship that
allows NULLs
Many-to-Many Relationships
Super-Types and Sub-Types
Self-Referencing Relationships
Lesson 2: Planning Referential Integrity

• Options for Implementing Referential Integrity


• Cascading Referential Integrity
Options for Implementing Referential Integrity

• Declarative referential integrity


• Enforces integrity by using foreign key constraints
• Prevents changes that violate referential integrity from
occurring

• Procedural referential integrity


• Enforces integrity by using triggers
• Allows changes to occur and then rolls back changes
that violate referential integrity
Cascading Referential Integrity
Lab 4: Planning and Implementing Referential Integrity

• Exercise 1: Planning Referential Integrity


• Exercise 2: Implementing Referential Integrity by
Using Constraints
• Exercise 3: Implementing Cascading Referential
Integrity

Logon Information
Ensure that the 10985C-MIA-DC and 10985C-MIA-SQL
virtual machines are both running, and then log on to
10985C-MIA-SQL as ADVENTUREWORKS\Student with
the password Pa55w.rd.

Estimated Time: 60 minutes

Potrebbero piacerti anche