Pages

Tuesday 24 November 2015

SQL SERVER ( CONSTRAINTS ) REAL TIME INTERVIEW QUESTIONS AND ANSWERS

1. What is Data Integrity?
Data integrity is an important feature in SQL Server. When used properly, it ensures that data is accurate,correct,and valid.
2. What are the Constraints?
Table constraints define rules regarding the values allowed in columns and are the standard mechanism for enforcing integrity.SQL Server 2000 supports five classes of constraints.NOT NULL,CHECK,UNIQUE,PRIMARY KEY,FOREIGN KEY.  
3. What are defaults? Is there a column to which a default can't be bound?
A default is a value that will be used by a column,if no value is supplied to that column while inserting data.
4. What is PRIMARY KEY?
A Primary Key is constraint is a unique identifier for a row within a data base table.It doesn't accepts duplicates and null values.
5. What is UNIQUE KEY Constraint?
 A Unique constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered.It can accept only one NULL.
6. What is FOREIGN KEY?
 A Foreign Key is a column that references  a column of another table. The purpose of the foreign Key is to ensure referential integrity of the data.
7. What is CHECK Constraint?
A check constraint is used to limit the values that can be placed in a column.The check constraints are used to enforces domain integrity.
8. What is NOT NULL Constraint?
A NOT NULL constraint enforces that the column will not accept null values.The not null constraints are used to enforce domain integrity, as the check constraints.
9. What is different in Rules and Constraints?
Rules and Constraints are similar in functionality but there is a little difference between them.Rules are used for backward compatibility.One the most exclusive difference is that we can bind rules to a data types where as constraints are bound only to columns.So we can create own data types with the help of Rules and get the input according to that.
10. What is the difference between a PRIMARY KEY and UNIQUE KEY?
 Both primary key and unique enforce uniqueness of the column on which they are defined.But by default primary key creates a clustered index on the column,where as unique creates a non clustered index by default.Another major difference is that ,primary key doesn't allow NULLs,But unique key allows only one NULL.
11. Difference candidate key, alternate key and composite key?
A candidate key is one that can identify each row of a table uniquely.Generally a candidate key becomes the primary key of the table .if the table has more than one candidate key ,one of them will become the primary key ,and rest are called alternate keys.
A key formed by combining at least two or more columns is called composite key.
12. Try to use constraints instead of triggers, whenever possible?
13. What is the use of DBCC Commands?
DBCC stands for database constistency checker.We use these commands to check the consistency of the database.
i.e.,maintenance,validation task and status checks.
Ex: DBCC CHECKDB - Ensures that tables in the DB and indexes are correctly linked.
DBCC CHECALLOC-To check that all pages in a DB are correctly allocated.
14. Have you ever used DBCC Command? Give an example for it?
15. How do you use DBCC Statements to monitor various aspects of a SQL Server  installation?
16. What is a Surrogate Key? What is the difference between Primary and Unique Key? What is the difference Primary and Surrogate Key?
17. Difference between column level check constraint and  table level check constraint?
18. How many check constraints for a table?
19. What is the difference between check constraints and trigger?
20. I want create check constraint on salary column as salary>0 but existing data already constain negative values as shown below. What happen if conflict occurs?

No comments:

Post a Comment