create table dep( --部门表
id int not null CONSTRAINT PK_dep_id PRIMARY KEY NONCLUSTERED,
name varchar(50)
)
go
create table employee( --员工表
id int not null CONSTRAINT PK_emp_id PRIMARY KEY NONCLUSTERED,
name varchar(50),
depid int not null,
CONSTRAINT FK_employee_dep FOREIGN KEY (depid)
REFERENCES dep (id) ON UPDATE CASCADE
)
go
insert dep select 2,'销售部'
union all select 3,'人事部'
go
insert employee select 1,'张三',2
union all select 2,'李四',3