一、增:有3種方法
1.使用insert插入單行資料:
2.使用insert,select語句將現有表中的 資料加入到已有的新錶中insert [into] 《表名》 [列名] values
《列值》
insert
into strdents (name,age) values ('atm',12)
3.將資料插入原表中(生成測試資料用的較多)insert
into
《已有的新錶》 《列名》 select
《原表列名》 from
《原表名》
insert
into newtable (name,class)select name,class from tableinfo
和另外一種方法一樣,僅僅是拷貝到原表中
二、刪:有3中方法insert
into tableinfo ('name','class')select name,class from tableinfo
1.delete刪除
2.truncate table 刪除整個表的資料delete
from
《表名》 [where
《刪除條件》]
delete
from tableinfo where name='atm'
3、drop刪除truncate
table
《表名》
truncate
table tableinfo
刪除表的全部行。但表的結構、列、約束、索引等不會被刪除;不能用於有外建約束引用的表
三、update更新改動drop
table
《表名》
drop
table tableinfo
刪除表中全部行。表結構也刪除了。
四、查update
《表名》 set
《列名=更新值》 [where
《更新條件》]
update tableinfo set age=12
where name='atm1'
set後面能夠緊隨多個資料列的更新值(非數字要引號);
1.普通查詢
2.模糊查詢select
《列名》 from
《表名》 [where
《查詢條件表達試》] [order
by《排序的列名》[asc或desc]]
1).查詢全部資料
select * from tableinfo
2).查詢部分行列--條件查詢
select name,age from tableinfo where age=11;
3).在查詢中使用as更改列名
select name as 姓名 from a where age=11;
4).查詢空行
select name from tableinf where class is
null
5).查詢返回限制行數(關鍵字:top )
select top 6 name from tableinfo
顯示列name的前6行,oracle 中用rownum替代(select * from a where rownum<6 )
6).查詢排序(關鍵字:order
by , asc , desc)
例:select name from tableinfo where age>=11
order
bydesc(默覺得asc公升序)
1).使用like進行模糊查詢
請看還有一篇文章, sql like四種使用方法
2).使用between在某個範圍內進行查詢
select * from tableinfo where age between 11
and22
3).使用in在列舉值內進行查詢(in後是多個的資料)
select name from tableinfo where name in ('atm','atm1','atm2');
SQL 增刪改查
之前大致了解過,現在用 mysql 的還是居於多數,而且自己之後也有意嚮往大前端發展,所以就需要撿起以前的 sql,也希望將來有機會用 node.js mysql 做大型專案的機會。因此,就從簡單的 sql 的增刪改查開始大前端之路。開發中最常見的就是 select 查詢。簡單的查詢,看起來是這樣的...
SQL增刪改查
1 增 insert into table name values value1,value2,insert into table name 列1,列2,values 值1,值2,2 刪 delete from table name where 列名稱 值 3 改 update table name...
sql增刪改查語法
1.使用insert插入單行資料 語法 insert into 表名 列名 values 列值 例 insert into strdents 姓名,性別,出生日期 values 斌 男 1993 6 15 注意 into可以省略 列名列值用逗號分開 列值用單引號因上 如果省略表名,將依次插入所有列 ...