MySQL一條語句更新多個表的方法

2021-09-21 06:39:19 字數 939 閱讀 8907

mysql本身是支援一條update語句更新多個表的,有時候這是非常有用的乙個特性。

update [low_priority] [ignore] table_references

set col_name1= [, col_name2=] …

[where where_condition]

於是繼續找table_references說明; 

table_references:

escaped_table_reference [, escaped_table_reference] …

escaped_table_reference:

table_reference

| table_reference:

table_factor

| join_table

table_factor:

tbl_name [[as] alias] [index_hint]

| table_subquery [as] alias

| ( table_references )

在我的另一篇文章中,我已經用到了該語法:

update table_a,table_b set table_a.age=table_b.age where table_a.id=table_b.id;

該語句中的table_b表也可以換成子查詢、join子句,比如:

update table_a,(select id,age from table_b) as tb set table_a.age=tb.age where table_a.id=tb.id;

mysql update官方文件: 鏈結

ORACLE SQL一條語句同時插入多個表

今天在網上看到乙個貼子,用一條語句,將資料同時插入多個表中,覺得很新奇,就自己練了一下,將語句記錄下來 step1 建立三個表,用於實驗測試 create table t table object id number,object name varchar2 128 object type varc...

2 更新一條MySQL語句到底發生了什麼?

1.redolog binlog 2.剖析 update t set c c 1 where id 2 3.redolog兩階段 prepare commit 4.設定redolog binlog持久化到磁碟 寫在開頭 本文涉及的資料庫語句 create table t id int primary...

檢視一條mysql語句的效能

mysql資料庫在5.0.37版本後新增了show profiles功能,可以分析出一條sql語句的效能。檢查資料庫是否支援show profiles功能 show variables like version 檢視profiles是否開啟 show variables like pro 開啟命令 ...