MySQL 增刪查改

2022-06-17 14:12:11 字數 2853 閱讀 6922

目錄2 insert

3 update

4 delete

5 更新和刪除的指導原則

此語句使用select語句檢索單個列。limit 5指示 mysql 返回不多於 5 行。

select prod_name

from products

limit 5, 5;

limit 5, 5指示mysql返回從行 5 開始的 5 行。第乙個數為開始位置,第二個數為要檢索的行數。

顧名思義,insert是用來插入(或新增)行到資料庫表的。插入可以用幾種方式使用:

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);

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');

insert into customers(cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country)

values('m. martian', '42 galaxy way', 'new york', 'ny', '11213', 'usa');

假如你想從另一表中合併客戶列表到你的 customers 表。不需要每次讀取一行,然後再將它用insert插入,可以如下進行:

insert into customers(cust_id,

cust_contact,

cust_email,

cust_name,

cust_address,

cust_city,

cust_state,

cust_zip,

cust_country)

select cust_id,

cust_contact,

cust_email,

cust_name,

cust_address,

cust_city,

cust_state,

cust_zip,

cust_country

from custnew;

為了更新(修改)表中的資料,可使用update語句。可採用兩種方式使用update

update customers

set cust_email = '[email protected]'

where cust_id = 10005;

update customers

set cust_email = '[email protected]';

update customers

set cust_name = 'joy',

cust_email = '[email protected]'

where cust_id = 10005;

為了刪除某個列的值,可設定它為null(假如表定義允許null值)。

update customers

set cust_email = null

where cust_id = 10005;

為了從乙個表中刪除(去掉)資料,使用delete語句。可以兩種方式使用delete

delete from customers

where cust_id = 10006;

delete from customers;
下面是許多 sql 程式設計師使用updatedelete時所遵循的習慣。

MySQL 增刪查改

create table ceshi1 uid varchar 50 primary key,pwd varchar 50 name varchar 50 1.最後一列不寫逗號 2.多條語句一起執行 分號分開 3.符號 英文狀態 1.主鍵 primary key 2.非空 not null 3.自增...

mysql增刪查改

語法 insert into 表名 欄位名1,欄位名2,values 值1,值2,舉例 insert into student id,name,grade values 1,zhangshan 98 若不指定欄位名,則新增的值的順序應和字段在表中的順序完全一致。語法 insert into 表名 v...

的增刪查改 MySQL定義庫表,增刪查改

mysql sql語言 ddl語句 資料庫定義語言 資料庫,表,檢視,索引,儲存過程 dml語句 資料庫操縱語言 插入資料insert,刪除資料delete,更新資料update dql語句 資料庫查詢語言 查詢資料select dcl 語句 資料庫控制語言 例如控制使用者的訪問許可權grant,r...