DML的具體內(nèi)容
1.插入數(shù)據(jù)
名字 | SQL語句 | 注意說明 |
---|---|---|
完全插入 | insert into 表名 (列名1伯顶,列名2球散,...) values(列值1傀蓉,列值2,.....)填帽; | 在表名后給出要插入的列名评也,在values后面給出列值瞳脓,值得順序和個數(shù)必須與前面指定的列對應(yīng)。 |
不完全插入 | insert into 表名 (列名1) values(列值1)翁涤; | 沒有指定的列等同于插入null值 |
不指定列名的完全插入 | insert into 表名 values(列值1桥言,列值2,列值3)葵礼; | 1:沒有給出要插入的列号阿,那么表示插入所有列。2:值得個數(shù)必須是該表列的個數(shù)3:值的順序鸳粉,必須與表創(chuàng)建時給出的列順序相同 |
2.刪除數(shù)據(jù)
名字 | SQL | 語句解釋 |
---|---|---|
刪除數(shù)據(jù) | delete from 表名 [where 條件]; | 刪除表的數(shù)據(jù)扔涧,不刪除表結(jié)構(gòu),指定條件届谈,只刪除指定的數(shù)據(jù) |
刪除數(shù)據(jù) | truncate table 表名枯夜; | truncate 是DDL語句,它是刪除整個表艰山,在create這個表湖雹,從而達(dá)到刪除表里數(shù)據(jù),只保留表結(jié)構(gòu)曙搬,并且無法回滾摔吏。 |
3.修改數(shù)據(jù)
名字 | SQL語句 |
---|---|
更新修改數(shù)據(jù) | update 表名 set 列名1=列值1,列名2=列值2纵装,....[where 條件] |
注釋:條件必須是一個boolean類型的值或表達(dá)式:例如:update t_person set gender=‘男’,age=age+1 where name='ZhangSan';|
運算符名
字解 | 解釋 | 例子 |
---|---|---|
=征讲、!=、>橡娄、<诗箍、>=、<=瀑踢、 | 等于扳还,不等于,大于橱夭、小于氨距、大于等于、小于等于,等于在set后棘劣,相當(dāng)于賦值俏让,在其他是等于的意思 | update 表名 set age=18 where name='ZhangSan'; |
between....and | 介于什么之間 例子: where age>=27 and age<=28 等同于 where age between 27 and 28update | 表名 set age=age+1 where age>=27 and age<=28 ; |
in(....) | 和括號里面的元素,有一個相同的即可茬暇,相當(dāng)于 或or | update 表名 set age=36 where name in ('Zhangsan','LiSi'); |
is null | 檢查是否有空值 | update 表名 set age=age+1 where age is null; |
not | 去反 | update 表名 set age=age+1 where age is not null; |
or | 或 | select 列名首昔,列名 from 表名 where 列名 = '數(shù)據(jù)' or 列名 = '數(shù)據(jù)'; |
and | 并且 | select 列名糙俗,列名 from 表名 where 列名 =‘?dāng)?shù)據(jù)’ and 列名 =‘?dāng)?shù)據(jù)'勒奇; |
本文來自 biubiuqiu 的CSDN 博客 ,全文地址請點擊:https://blog.csdn.net/qq_39852472/article/details/80594241?utm_source=copy