SQL constraints are used to specify rules for the data in a table. In SQL, we have the following constraints:
• NOT NULL - Indicates that a column cannot store NULL value
• UNIQUE - Ensures that each row for a column must have a unique value
• PRIMARY KEY - A combination of a NOT NULL and UNIQUE.
• FOREIGN KEY - Ensure the referential integrity of the data in one table to match values in another table
• CHECK - Ensures that the value in a column meets a specific condition
• DEFAULT - Specifies a default value when specified none for this column
Create Table Person (id int Primary key, Name Varchar(25) Not Null , Address Varchar(25) Default 'Delhi' , Phone_No Varchar(11) Not Null )
Create table Order (oid int foreign key references Person(id), Item_Code varchar(25) Unique, Description Varchar(25),
Quantity int check ( quantity >= 0 ), Price float(6), OrderDate date Default Getdate( ) )
Select * from Order where OrderDate between '2000-01-01' and '2014-12-31'
Select * from Order where OrderDate like '2014%'
Select * from Order where OrderDate not like '2013%'