Interview FAQs

FAQs of level

A constraint is the restriction, placed at either column or table level. A constraint ensures that your data meets certain data integrity rules.
There are three types of constraints in SQL Server -

1. Domain Constraint - deals with one are more columns.
2. Entity Constraint - are all about individual rows.
2. Referential Integrity Constraint - are created when a value in one column must match the value in another column - in either the same table or in a different table.

Primary keys are the unique identifiers for each row in a table. They must contains unique values (and hence can not be NULL). Because of their importance in the relational database, primary keys are the most fundamental of all keys and constraints.

A table can a maximum of one primary key. A primary key ensures uniqueness within the columns declared as being part of that primary key and that unique value serve as an identifier for each row.

There are two ways to create a primary key -

1. With a create table command.
2. With an alter table command.

FOREIGN KEYs are both a method of ensuring data integrity and a manifestation of the relationships between tables. When you add a FOREIGN KEY to a table, you create a dependency between the table for which you define the FOREIGN KEY (the referencing table) and the table your FOREIGN KEY references (the referred table). After adding a FOREIGN KEY, any record you insert into the referencing table must have a matching record in the referenced column(s) of the referenced table, or the value of the FOREIGN KEY column(s) must be set to NULL.
UNIQUE KEY constraint requires a unique value throughout the named column (or combinations of the columns) in the table. Unlike the primary key a UNIQUE KEY constraint does not automatically prevents you from having a NULL value. Whether NULLs are allowed or not depends on how you set the NULL option for that column in the table. Keep in mind, however, that, if you do allow NULLs, you will able to insert only one of them.
Business rule validation can be applied to a table by using CHECK constraint. CHECK constraint must be specified as a logical expression that evaluates either to TRUE or FALSE.

A CHECK constraint takes longer to execute as compared to NOT NULL, PRIMARY KEY, FOREIGN KEY or UNIQUE constraints. Thus CHECK constraint must be avoided if the constraint can de defined using NOT NULL, PRIMARY KEY, FOREIGN KEY constraints.

Bu default, you can not delete a record or update the referenced column in a referenced table if that record is referenced from the dependent table. If you want to be able to delete or update such records, then you need to set up a CASCADE action for the delete and/or update.
PreviousDisplaying 6 of 15Next
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Need Help? Contact Us.

Log in


Forgot password?


New User