MySQL插入更新刪除資料

2022-05-07 12:06:11 字數 1906 閱讀 8968

insert into customers

values(null,

'pep e. lapew',

'100 main street',

'los angeles',

'ca',

'90046',

'usa',

'null',

'null');

insert into customers(cust_name, 

cust_address,

cust_city,

cust_state,

cust_zip,

cust_country,

cust_contact,

cust_email)

values('pep e. lapew',

'100 main street',

'los angeles',

'ca',

'90046',

'usa',

'null',

'null');

如果對錶中不允許null值且沒有預設值的列不給出值,則mysql將產生一條錯誤訊息,並且相應的行插入不成功。

insert into customers(cust_name, 

cust_address,

cust_city,

cust_state,

cust_zip,

cust_country)

values('pep e. lapew',

'100 main street',

'los angeles',

'ca',

'90046',

'usa'),

('m. martian',

'42 galaxy way',

'new york',

'ny',

'11213',

'usa');

insert into customers(cust_id,

cust_email,

cust_name,

cust_address,

cust_city,

cust_state,

cust_zip,

cust_country)

select cust_id,

cust_country,

cust_email,

cust_name,

cust_address,

cust_city,

cust_state,

cust_zip,

cust_country

from custnew;

mysql> update customers 

set cust_email='[email protected]'

where cust_id=10005;

query ok, 1 row affected (0.02 sec)

rows matched: 1 changed: 1 warnings: 0

update ignore customers…
mysql> delete from customers 

where cust_id=10006;

query ok, 1 row affected (0.01 sec)

如果省略了where子句,則update或delete將被應用到表中所有的行。換句話說,如果執行update而不帶where子句,則表中每個行都將用新值更新。類似地,如果執行delete語句而不帶where子句,表的所有資料都將被刪除。

MySQL插入更新刪除資料

更新資料 select from person where id 10 update person set age 15,name liming where id 10 select from person where id 10 update person set info student whe...

MySQL 插入 更新 刪除資料

我們吧檢索單獨拉出去,是因為在jdbc中對於檢索的處理,和對於插入,更新,刪除操作是不同的。現在我們將分別介紹mysql的insert插入語句,update更新語句,delete刪除語句。part 1 插入資料 sql語句中,insert是用來插入的 或新增 插入或新增乙個行到資料庫中。有以下幾種方...

MySQL 插入 更新 刪除資料

插入 更新 刪除資料 一 插入資料 插入資料使用 insert 語句向表插入資料記錄,插入資料有四種方式,即為所有字段插入資料 為指定字段輸入資料 同時插入多條資料以及插入查詢結果。先建立乙個表,方便下面舉例 create table student stu id int 10 primary ke...