MySQL基礎知識 插入、刪除

1、插入多條

insert into cust_info(cust_name,
    cust_tele,
    cust_address)
values(
    'Pep E',
    '15988888888',
    'shanghai'
),
values(
    'M.Martian'
    '17799999999',
    'beijing'
);

2、insert select語句

insert into cust_info(cust_name,
    cust_tele,
    cust_address)
select cust_name1,        //對應列的名稱可以不同,insert並不關心名稱,只是對應項插入
    cust_tele1,
    cust_address1
from cust_info_1
where cust_id1<=100;

3、更新多個數據

update cust_info            //使用update ignore cust_info可以忽略更新時的錯誤
set cust_name='zhangsan',    
    cust_address='beijing',
    cust_qq=NULL            //允許更新爲NULL
where cust_id=1005;

4、刪除記錄

delete from table_name
where col_prim='...';

5、刪除表中的每一條記錄,使用truncate table語句比不帶where 的delete語句要更快

6、視圖的理解:視圖中沒有數據,視圖實際上 是方便查詢的,而不是用於更新、刪除(某些情況下也可以,看能不能確定基表中需要操作的數據)。可以把從視圖中的檢索,看做是對定義視圖的時候的select結果集的檢索。

示例1



示例2:重新格式化檢索出來的數據



示例3:視圖過濾掉不需要的數據



示例4:視圖與計算字段




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章