在查询用户的权限的时候 使用左外连接 和 access数据库中左外连接

一般做视图最好是做成左外连接的。而其作用尤其在我们查询用户当前的权限时尤为明显,我们将 权限表即模块表放→角色权限表→角色表→用户角色表→用户表 就这样left outer join 连接起来,这样就保证了该用户的所用权限都能查询出来。

access数据库中的左外连接很特别,它是先写里面的然后逐步扩展到最后,先执行里面的。

例子

SELECT xt_user.Pkid, xt_user.UserID, xt_user.UserName, xt_user.Password, xt_user.Status, xt_module.ModuleName
FROM (((xt_module LEFT JOIN xt_rolemodule ON xt_module.Pkid = xt_rolemodule.ModulePkid) LEFT JOIN xt_role ON xt_role.Pkid = xt_rolemodule.RolePkid) LEFT JOIN xt_userrole ON xt_role.Pkid = xt_userrole.RolePkid) LEFT JOIN xt_user ON xt_user.Pkid=xt_userrole.UserPkid;

posted @ 2015-01-07 09:16  keyboard3  阅读(384)  评论(0编辑  收藏  举报