Sql中同时删除更新多张表的数据
初学者可能对同时更新,删除,操作多张表存在疑惑或是一个SQL一个方法此方法造成了代码冗余
操作方法
- 01
<delete id="DeleteStuDent" parameterClass="String"> BEGIN DELETE FROM Student where StuID=#StuID#; DELETE FROM Score where ScoreID=#ScoreID#; DELETE FROM Class where ClassID=#ClassID#; DELETE FROM Teacher where TeacherID=#TeacherID#; END; </delete>
- 02
<update id="UpdateStudent" parameterClass="StudentEntity"> BEGIN UPDATE Student SET StuName=#StuName#,StuAge=#StuAge# WHERE StuID=#StuID#; UPDATE Score SET StuState=2 where StuID=#StuID#; ; UPDATE Class SET ClaState =2 where StuID=#StuID#; ; UPDATE Teacher SET TeacherState =2 where StuID=#StuID#; ; END; </update>
- 03
一个方法 通过begin end 语句块吧同时执行的SQL语句包含起来,同时以分号隔开即可
赞 (0)