Mysql 不同場景下運算元據庫表

2022-09-20 10:24:11 字數 527 閱讀 6986

1. 通過關聯欄位把一張表的字段值更新另一張表的字段值

update table_a a, table_b b set a.username = b.username where a.id =b.id;

--以下2種更新結果以table_b的查詢結果為準,table_b中沒有查到的記錄會全部被更新為null,相當於外連線

update table_a a set username = (select name from table_b where id =a.id);

update table_a a left join table_b b on a.id= b.id set a.username = b.name;

2. 將查詢結果插入另一張表

-- insert into 表1(列名) select(列名) from 表2;

insert into table_a(username) select name from table_b where id=1;

3.待更新

MySQL運算元據庫表

1,建立表的時候寫注釋 create table if not exists demo dictionary id varchar 32 not null comment 主鍵id primary key,dictionary name varchar 100 not null comment 名稱...

運算元據庫 表

1 連線到mysql伺服器 mysql u使用者名稱 p2 檢視全部資料庫 show databases 3 選擇要操作的資料庫 use 資料庫名稱 4 檢視某個資料庫的所有表 show tables 運算元據庫 建立資料庫 create database 資料庫名稱 刪除資料庫 drop data...

MySQL 運算元據庫

資料庫是指長期儲存在計算機內,有組織的 可共享的資料集合。簡而言之,資料庫就是乙個儲存資料的地方。只是,其儲存方式有特定的規律。這樣可以方便處理資料。資料庫的操作包括建立資料庫和刪除資料庫。這些操作都是資料庫管理的基礎 建立資料庫是指在資料庫系統中劃分一塊空間,用來儲存相應的資料。這是進行表操作的基...