我创建了3个表,即员工,部门和EmpDept。
1)员工表字段是
: - EmployeeID(主键),Fname, Lname,年龄,薪水,地址
2)部门表字段为: -
DepartmentID(主键),DeptName,DeptLocation
3)EmpDept表字段为: -
ID(主键),EmpId(Foriegn Key reference Employee表) ,DeptID(外键引用部门表)
我想执行以下操作: -
a)从表Employee和Department中选择所有字段
b)删除特定部门还会删除属于该特定部门的员工表中的所有员工。
我没有得到第3表中包含哪些字段(即EmpDept)以及如何应用连接来选择列
我的尝试
create procedure EmpDept2
as
Begin
select Employees.EmployeeID
, Employees.FirstName
, Employees.LastName
, Employees.Age
, Employees.CreatedDate
, Employees.LastModifiedDate
, Employees.ModifiedBy
, Employees.Active
,Department.DepartmentID
, Department.DeptName
from Employees, Department inner join EmpDept
on EmpDept.EmpId = Employees.EmployeeID
on EmpDept.DeptId= Department.DepartmentID
答案 0 :(得分:1)
create procedure EmpDept2
as
Begin
select Employees.EmployeeID
, Employees.FirstName
, Employees.LastName
, Employees.Age
, Employees.CreatedDate
, Employees.LastModifiedDate
, Employees.ModifiedBy
, Employees.Active
,Department.DepartmentID
, Department.DeptName
from Employees inner join EmpDept
on EmpDept.EmpId = Employees.EmployeeID
inner join Department
on EmpDept.DeptId= Department.DepartmentID
END
一次加入两个表,然后加入条件ON你要加入它们的内容,然后再次逐个添加其他表,指定你想加入它们的条件。