SQL Server -Constraints - DotNet and DataBase

Follow us on Facebook

SQL Server Mountain View Mountain View Mountain View

Tuesday, 31 July 2018

SQL Server -Constraints

  The constraint is nothing but a rule. We can define rules to monitor data while inserting, deleting updating in a table.

                There are 6 Types of Constraints in SQL Server.
                1.     Primary Key Constraint
                2.     Unique Key Constraint
                3.     Foreign Key Constraint
                4.     Not null Key Constraint
                5.     Check key Constraint
                6.     DEFAULT key Constraint                                                                 

Primary Key Constraint (PK) – Primary key constraint is to maintain uniqueness in the table. PK doesn’t allow duplicates and null values.
Unique Key Constraint – The Unique key is also to maintain uniqueness in the records. But you can enter one null value into the table column.
Foreign Key Constraint(FK) – Foreign key dependent on the Primary key. It allowed entering the values which are accepted by the related Primary key.  FK is used to restrict the junk data.
Not null Key Constraint - Not null key is used to restrict null values enter into the columns.
Check Key Constraint – Check key is used to enter the validated data only into the table columns. While inserting data, we can check the value s per mentioned norms or not.
DEFAULT Key Constraint – Default Key is used to enter default values into the table column in case null values entered.           
Interview questions:                                 

                1. What is a Constraint?
                2. How many constraints are there in SQL Server? 

No comments:

Post a comment


Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.