Access中怎么做CRUD增删查改
Access中怎么做CRUD增删查改?怎么使用GROUP BY, HAVING, LIKE , between and ? 这篇经验将告诉你。
工具/原料
Access
SQL基础知识
往数据表中新增一条记录INSERT
1、所有的CURD操作,都可以在SQL View中进行。如果不知道怎么在Access中写SQL语句,可以参看我的另一篇经验:Access中如何写SQL语句?比如,我要往students表中添加一条新的记录,S_ID为6。添加该记录前,数据表中的记录如图所示:




数据表中删除一条记录DELETE
1、比如我们想删除 Students表中S_ID为6的那条记录。对应的DELETE语句为:DELETE *FROM studentsWHERE s_id = 6;点击Run执行该DELETE语句

2、到数据表中查看数据,发现S_ID为6的那条记录被删除了。有意思的是,该记录对应位置的每个列的内容全部更改为Deleted了,但是,这种更改是暂时的。当你退出该数据库,再次查看该数据表的时候,这条特殊记录就不显示了。S_ID为6的那条记录被彻底删除了。











11、SELECT操作示例10:使用子查询,查询所有学习Smith老师课程的学生。这个查询涉及到3张表:students,Enrollment, subjects。第一步: 在 subjects表中查询'Smith'老师所教授课程的subject_idselect subject_id from subjects where subject_teacher = 'Smith'第二步:在 enrollment表中查询学习该课程的student的student_idselect Student_ID from Enrollment where Subject_ID in (第一步的结果)第三步:在students表中根据 student_id查询出对应的记录SELECT *FROM studentsWHERE S_Id in (第二步的结果)所以,最终的SQL语句为:SELECT *FROM studentsWHERE S_Id in ( select Student_ID from Enrollment where Subject_ID in ( select subject_id from subjects where subject_teacher = 'Smith'));

12、SELECT操作示例11:使用JOIN,查询所有学习Smith老师课程的舌哆猢筢学生。这个查询涉及到3张表:students,Enrollment, subjects。SQL语句相比子查询更简洁些,而且不仅仅可以查询出students表中的记录,还可以查询出subjects表中的记录。SELECT U.*, S.subject_name, S.subject_teacherFROM enrollment AS E, subjects AS S, students AS UWHERE E.subject_id = S.subject_id AND E.student_id = U.s_id AND s.subject_teacher = 'Smith'

13、SELECT操作示例12:使用子查询查询年龄最大的学生的记录。SELECT LastName, FirstName, int( (Date()-BirthDate)/365 ) AS AgeFROM studentsWHERE int( (Date()-BirthDate)/365 ) in ( select max( int( (Date()-BirthDate)/365 ) ) from students);
