1. 更新关联表中的数据
update Staff a,[section] b
set a.eSection=b.SectionID
where a.eSection=b.SectionName
标准SQL:
update a
set a.eSection=b.SectionID
From Staff a,[section] b
where a.eSection=b.SectionName
2. 一对多表查询
SELECT DistinctRow a.eID, a.eNumber, a.eName, Department.DepartmentName,Section.SectionName,a.eIDCARD,
a.eSex,ZZMM.ZZMM,a.eMZ,a.eCJGZ,a.eBDSJ,a.eXX,a.eXL,a.eZY,
a.ePosition,PositionType.PositionType,ZWJB.ZWJB,ZWJB2.ZWJB2,
ZWZG.ZWZG,a.eZSBH,a.eZSSJ,ZYNL.ZYNL,ZYNLJB.ZYNLJB,a.eZSBH2,
a.eZSSJ2,a.eContract,WorkStatus.WorkStatus,a.eHomeAddr,a.ePhoneNumber,
a.eBirthday,a.eAge,a.eWorkYears,a.eWageBankId,a.eBonusBankId,
a.eExtMember,a.eMemo
FROM (((((((((Staff AS a LEFT JOIN Department ON a.eDepartmentId = Department.DepartmentId) LEFT JOIN PositionType ON a.ePositionTypeID = PositionType.PositionTypeID) LEFT JOIN [Section] ON a.eSectionID = Section.SectionID) LEFT JOIN WorkStatus ON a.eWorkStatusID = WorkStatus.WorkStatusID) LEFT JOIN ZWJB ON a.eZWJBID = ZWJB.ZWJBID) LEFT JOIN ZWJB2 ON a.eZWJB2ID = ZWJB2.ZWJB2ID) LEFT JOIN ZWZG ON a.eZWZGID = ZWZG.ZWZGID) LEFT JOIN ZYNL ON a.eZYNLID = ZYNL.ZYNLID) LEFT JOIN ZZMM ON a.eZZMMID = ZZMM.ZZMMID) LEFT JOIN ZYNLJB ON a.eZYNLJBID = ZYNLJB.ZYNLJBID;
3.如何判断表是否存在?
select name from msysobjects where flags = 0
注意msysobjects默认是不能访问的,需要设置一下:
1. 打开Access
2. 点击“工具”菜单,选择“选项”
3. 在“视图”页上,将“系统对象”勾上
4. 点击“确定”按钮保存设置
5. 点击“工具”菜单,选择“安全”中的“用户与组权限”
6. 选择“权限”页
7. 在“对象类型”下拉列表中选择“表”
8. 在“用户名/组名”中选择“管理员”用户
9. 在“对象名称”中选择“MSysObjects”表
10. 在“权限”中将“读取数据”勾上
11. 点击“确定”按钮保存设置