Tuesday, October 6, 2020

SQL Constraints


   What are SQL Constraints ?

  SQL Constraints specify  rules for data in a table.It basically limit the type  of

  data that go into the table.Let us see the type  of  constraints used in table.

   1. Primary Key:Uniquely Identifies each row in a table

   2. Foreign Key: Uniquely Identifies a row in another table

   3. Not Null: It ensures that a column should not have a Null value

   4. Unique:It ensures that all the values in the column are unique

   5. Check:It ensures that the values in the column satisfy a specific condition

   6. Default:It is used to set a default value to a column if no value is specified


 Constraints  are basically  specified during creation of  a table statement or during

 alter table statement.

 Syntax:  Create table tablename

               { column1 datatype constraint,

                  column2  datatype constraint,

                  column3 datatype constraint

             };  

 For eg:

   Create table customer

{   customerid int Primary key,

     customername text,

    customeraddress text

};

   


   

    

No comments:

Post a Comment