1. 程式人生 > >多表更新:update,join

多表更新:update,join

1、多表更新:

  下面我建兩個表,並執行一系列sql語句,仔細觀察sql執行後表中資料的變化,很容易就能理解多表聯合更新的用法。

前期準備工作:

update join_teacher_class join join_teacher
    on join_teacher_class.t_id=join_teacher.id
    set begin_date='0000-00-00',t_name='老夫子'
    where join_teacher.id=2;

1)檢視join_teacher表資訊:

2)檢視join_teacher_class表資訊:

3)查詢連線兩張表的資訊:

更新操作:

update join_teacher_class join join_teacher
on join_teacher_class.t_id=join_teacher.id
set begin_date='0000-00-00',t_name='老夫子'
where join_teacher.id=2;

後期操作:

1)檢視更新join_teacher表後的資訊:

2)檢視更新join_teacher_class表後的資訊:

3)檢視多表更新後的連線查詢資訊: