-->

Spiga

SQL SERVER Questions And Answers Page 2

1. What is a sub query?

Sometimes the results of one query are dependant on the results of another query. For this purpose one query is nested inside another query, this is called as sub query.

2. What are the types of constraints?

You can enforce data integrity by using constraints. Constraints are divided in to five categories.
Primary key constraint
A primary key constraint is defined on a column are a set of columns whose values uniquely identify the rows in a table. It cannot contain null values.
Unique constraint
Unique constraints are used to enforce uniqueness on non-primary key columns. It allows null values but only one row can have a null value.Multiple unique constraints can be created on a table.
Foreign Key constraint
You can use the foreign key constraint to remove the inconsistency in two tables when the data in the one table is dependant on the other table.
Check constraint
It enforces domain integrity by restricting the values to be inserted in a column. It is possible to define multiple check constraints on a single column. These are evaluated in the order in which they are defined.
Default Constraint
A default constraint can be use to assign a constant value to a column and the user need not insert values in to that column.

3.What is a rule?

The required integrity can be enforced by specifying a check constraint or by defining a rule. But check constraint modifies the table structure. The constraint can there fore be implemented using rules with out changing the table structure. This rule is applied before an insert or update statement .A rule must be bound to a column or a user-define d data type. This is done using stored procedure sp_bindrule. Rules do not apply to data that has already been inserted in the table. The existing values in tables do not have to meet the criteria specified by the rule.

There was an error in this gadget