20 更新和刪除資料

2021-08-07 11:42:59 字數 773 閱讀 7064

例:客戶10005有了email

update customers

set cust_email='[email protected]'

where cust_id=10005;

以要更新的表的名字開始;以where子句結束。

更新多個列值

update customers

set cust_name='fudd',//逗號分隔

set cust_email='[email protected]'

where cust_id=10005;

問題:更新多行時,若中間更新發生錯誤,則整個更新操作取消 ——ignore:

update  ignore customers//即使發生錯誤也能繼續更新
為了刪除某個列的值:
update customers

set cust_email=null

where cust_id=10005;

使用注意:

不要省略where,不然會刪除所有的行。

delete刪除的是表的內容,而不是表本身(drop)

若真的要刪除所有行,使用truncate table更快。

例:刪除客戶10006

delete from customers

where cust_id=10006;

更新和刪除資料

更新資料,即對錶中存在的資料進行修改。sql語句 update 語句 基本語法 update 表名 set 欄位名1 值1 欄位名2 值2,where 條件表示式 語法說明 欄位名1,欄位名2,用於指定更新的欄位名稱 值1,值2,用於表示字段更新的新資料。where條件表示式,可選引數,用於指定更新...

MYSQL 20 更新和刪除資料

使用update語句,採用兩種方法 1.更新表中特定行 2.更新表中所有行 基本的update語句由3部分組成,分別是 1.要更新的表 2.列名和他們的新值 3.確定要更新行的過濾條件 update customers set cust email 274857347 qq.com where cu...

新增,更新和刪除資料

為表中所有字段新增資料 通常情況下,向資料表中新增的新記錄應該包含表所有字段,即為該表中的所有字段新增資料,為表中所有字段新增資料的insert語句有兩種。1 insert語句中指定所有欄位名 執行成功後,會在表stu中新增一條資料。為了驗證資料是否新增成功,使用select語句檢視student表...