Pages

Friday, April 24, 2009

SQL Server Interview Question Answers -- Part 4

5) What is RULE?
A rule specifies the acceptable values that can be inserted into a column. This is similar to CHECK constraint.

11) What is the table name, that contains RULE Constraint definition?
Syscomments is the table which contains the RULE definition.
Use the below query to get the information.

select name as Rule_Name,
sc.TEXT as Rule_Definitionfrom sysobjects so inner join syscomments sc
on so.id = sc.id
where so.xtype='R'

15) Can you drop a Parent Table with out affecting its child tables?
No. First you need to drop all the Foreign Key relationships and then only you can drop Parent Table.

16) How to disable and Enable the constraints?
You need to use ALTER TABLE statement to disable constraint.
ex: ALTER TABLE ACCOUNT NOCHECK CONSTRAINT CHECK_IN_AMOUNT;
I will explain in-detail about disabling constraints in my next section.

17) What is the order of Constraints execution?
There is no predified order. All the constraints on the column gets executed.

18) what is difference between Primary Key, Unique Key and Alternative Key?
Primary Key ==> Is used to uniquely identify records and doesn't allow NULL values.
Unique Key ==> Is also used to uniquely identify records but does alow NULL Values per column combination.
Alternate Key ==> Is another type of Unique key, which is used to identify each record uniquely. This is not a constraint. This is just a terminology.


1) What is a Primary Key?
2) What is Unique Key?
3) What is the difference between Primary Key and Unique Key?
4) What is Check Constraint?
5) What is RULE?
6) What is the difference between RULE and Check Constraint?

7) How to create a relationship between two tables?
8) Can we create a Foreign Key with out Primary Key?
9) What is the table name,that contains the Primary Key, Unique Key and Foreign Key Information?

10) What is the table name, that contains Check Constraint Definition?
11) What is the table name, that contains RULE Constraint definition?
12) Can we have RULE and Check Constraint on the same column?
13) Can we apply Integrity Constraints on Computed Columns?
14) Can you write a query to find out the Child Table Name and Parent Table Name and the Columns to join?

15) Can you drop a Parent Table with out affecting its child tables?
16) How to disable and Enable the constraints?
17) What is the order of Constraints execution?
-- Questions from Readers of the DotNetVJ
18) what is difference between Primary Key, Unique Key and Alternative Key?

No comments: