DDL Lab3
DDL Lab3
SQL Constraints:
- SQL constraints are used to specify rules for the data in a table.
2. Primary key
4. Foreign key
5. check
1
6. default
7. unique
Ex:
Ex:
- Often this is the primary key field that we would like to be created
automatically every time a new record is inserted.
Identity
Or
2
EX:
Employees
emp_i F_nam mini L_nam ss bdat E_addres gende salar manage dn
d e t e n e s r y r o
use company
create table employees
(
emp_id int not null constraint pk_emp_eid primary key identity,
fname nvarchar(20) not null,
mname nvarchar(20) not null,
lname nvarchar(20) not null,
ssn nvarchar(14) not null,
badte date,
e_address nvarchar(100),
--salary1 money,
salary2 decimal(10,2) constraint ck_emp_salary check(salary2 between 1000 and
10000) constraint def_emp_salary default 3000,
gender nvarchar(5) constraint ck_emp_gender check(gender ='male' or gender
='female') constraint def_emp_gender default 'male',
dno int not null,
manager int constraint fk_emp_manager foreign key references employees(emp_id)
)