Friday, 6 January 2012

how to create table in sql server

create table dept
(
DID int identity constraint dept_did_pk primary key,
DNAME varchar(50) constraint dept_dname_nt not null,
LOC varchar(50) constraint dept_loc_ck check(LOC IN('PURI','BBSR','CTC','MUMBAI'))
)

create table EMP
(
EID INT identity constraint emp_eid_pk primary key,
[NAME] varchar(50) constraint emp_name_nt not null,
ADDRESS VARCHAR(50) constraint emp_address_uk unique,
SALARY money constraint emp_sal_nt not null,
DESIGNATION varchar(50) constraint emp_desig_nt not null,
MGR int,
DID int constraint dept_did_fk foreign key references dept(did) on delete cascade on update cascade,
constraint dept_sal_ck check((SALARY=50000 AND DESIGNATION='MANAGER') OR (SALARY=60000 AND DESIGNATION='HR'))
)

No comments:

Post a Comment