Constraints
constraint with example in sql server In Microsoft SQL Server , Constraints are rules applied on table columns to maintain data accuracy and integrity. Types of Constraints in SQL Server PRIMARY KEY FOREIGN KEY UNIQUE NOT NULL CHECK DEFAULT 1. PRIMARY KEY Constraint Uniquely identifies each record. Does not allow NULL . Example CREATE TABLE Students ( StudentID INT PRIMARY KEY , StudentName VARCHAR ( 100 ) ); 2. FOREIGN KEY Constraint Creates relationship between two tables. Example CREATE TABLE Department ( DeptID INT PRIMARY KEY , DeptName VARCHAR ( 50 ) ); CREATE TABLE Employee ( EmpID INT PRIMARY KEY , EmpName VARCHAR ( 100 ), DeptID INT , CONSTRAINT FK_Employee_Department FOREIGN KEY (DeptID) REFERENCES Department(DeptID) ); 3. UNIQUE Constraint Prevents duplicate values. Allows one NULL value. Example CREATE TABLE Users ( UserID INT PRIMARY KEY , Email VARCHAR ( 100 ) UNIQUE ); 4. NOT NULL Constraint Do...