我有一个为我正在制作的网站创建的数据库,其中包含员工列表。这将是一个网格状列表,包含每个员工的照片、姓名、电话号码等。
这是我的第一个数据库设计,我为此感到非常自豪……但我是新手,所以我确信它在某些方面效率低下。
我无法找出为网站查询它以制作元素的最佳方式。
1)我应该使用虚拟表吗?或者我应该只使用一个查询并为每个员工循环它?
2) 一些员工将拥有多个司法管辖区。现在我有:
select employees.firstName, employees.lastName, employees.phone, employees.position,
employees.picture, jurisdictions.jurisdiction
from employees
inner join(jurisdictions cross join departments cross join user_jurisdictions)
on (employees.deptID = departments.deptID
AND user_jurisdictions.userID = employees.userID
AND user_jurisdictions.jurID = jurisdictions.jurID)
哪个会返回:
+-----------+----------+--------------+-----------------+---------+--------------+
| firstName | lastName | phone | position | picture | jurisdiction |
+-----------+----------+--------------+-----------------+---------+--------------+
| John | Smith | 210-226-3232 | Senior Manager |/pics/jpeg1|South America|
| John | Smith | 210-226-3232 | Senior Manager |/pics/jpeg1|London |
+-----------+----------+--------------+-----------------+---------+--------------+
由于员工拥有额外的管辖权,有什么方法可以创建删除重复行的查询?就像是?
+-----------+----------+--------------+---------+---------+--------------+------------+
| firstName | lastName | phone | position| picture | jurisdiction |Jurisdiction|
+-----------+----------+--------------+---------+---------+--------------+------------+
| John | Smith | 210-226-3232 | Manager |/pics/jpeg1| South America|London |
+-----------+----------+--------------+-----------------+---------+-------------------+
这是我的mysql架构:
employees
--------------------
userID (primary key)
firstName
lastName
phone
fax
position
picture
deptID (foreign key references departments(deptID))
departments
--------------------
deptID (primary key)
department
jurisdictions
-----------------
jurID (primary key)
jurisdiction
user_jurisdictions
--------------------------
userID(foreign key references employees(userID))
jurID(foreign key references jurisdictions(jurID))
triger:
after_employees_insert | INSERT | employees | begin
insert into user_jurisdictions(userID) values (new.userID);