Data Integrity Enforcement, Constraints and Indexes Flashcards
Should you use rules or declarative constraints to enforce data integrity?
- Declarative constraints
- Rules are not as well suited for enforcing data integrity and will be deprecated in a future version of SQL Server
SQL Server 70-461 08-02
How are table constraints like views, tables, stored procedures, etc?
They are also considered database objects in SQL Server
SQL Server 70-461 08-02
What are the 5 different types of constraints?
- Primary key constraint
- Unique constraint
- Foreign key constraint
- Check constraint
- Default constraint
SQL Server 70-461 08-02
What does a UNIQUE CONSTRAINT allow you to do?
Enforce uniqueness of values in a column
SQL Server 70-461 08-02
What is automatically created when you create a UNIQUE CONSTRAINT?
- A unique index with the same name as constraint.
- The unique index is used to enforce the uniqueness of the column or combination of columns
SQL Server 70-461 08-02
Can you have NULLS in a column you want to have a unique constraint?
Yes, but only one of the rows can be null
SQL Server 70-461 08-02
Can PK constraints and Unique constraints be created on computed columns?
Yes
SQL Server 70-461 08-02
What is the max # of columns that can be the key columns of an index?
16
SQL Server 70-461 08-02
What is the max size in bytes that the key column(s) of an index can have?
900 bytes
SQL Server 70-461 08-02
How does a check constraint work?
- You create an expression similar to a filter expression in a WHERE clause so SQL Server knows how to identify valid values and only let them in.
- You can reference other columns in the same row and use built in functions.
SQL Server 70-461 08-02
What do you need to take into account when making a CHECK constraint column that allows nulls?
Make sure that the CHECK CONSTRAINT expression you create will allow nulls to get through
SQL Server 70-461 08-02
Can you customize an error message for if the CHECK CONSTRAINT fails?
No. You would have to use something like a trigger to do that
SQL Server 70-461 08-02
Can you reference the previous value of a column in the CHECK constraint expression?
No. You would need to use a trigger for something like that.
Example: Unit price cannot be increased bby more than 25%
SQL Server 70-461 08-02
What does a DEFAULT CONSTRAINT do?
Say a record is being inserted. For the insertion, column1 is null. DEFAULT CONSTRAINT basically says if the value is NULL instead assign this other value.
SQL Server 70-461 08-02
What happens if you don’t supply a name for a DEFAULT CONSTRAINT?
SQL Server will give it a machine generated name.
SQL Server 70-461 08-02