Beruflich Dokumente
Kultur Dokumente
• Domain Integrity
• Defines the allowed values in columns
• Entity Integrity
• Primary key uniquely identifies each row within a table
• Referential integrity
• Defines the relationship between tables
Options for Enforcing Data Integrity
• Data Types
• DEFAULT Constraints
• CHECK Constraints
• Demonstration: Data and Domain Integrity
Data Types
• Default constraints
• Provide default values for columns
• Used if INSERT provides no column value
• Must produce data compatible with the data type for
the column
CHECK Constraints
• Check constraints
• Limit the values that are accepted in a column
• Only rejects FALSE outcomes
• NULL evaluates to UNKNOWN and not FALSE
• Can be defined at table level to refer to multiple
columns
Demonstration: Data and Domain Integrity
• Primary keys
• Are used to uniquely identify a row in a table
• Must be unique and not NULL
• May involve multiple columns that form a composite
key
UNIQUE Constraints
• Unique constraints
• Ensure that values in a column are unique
• One row may have a NULL value
• You can have multiple unique columns
IDENTITY Constraints
• IDENTITY property
• Automatically generates column values
• You can specify a seed (starting number) and an
increment
• Default seed and increment are both 1
• SCOPE IDENTITY(), @@IDENTITY return current value
Working with Sequences
• Sequence objects:
• Are user-defined, schema-bound objects
• Are not tied to any particular table
• Can be used to ease migration from other database
engines
Demonstration: Sequences Demonstration
Logon Information
Virtual machine: 20762C-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa55w.rd
• Review Question(s)
• Best Practice