標籤:set 儲存 order by 修改 沒有 欄位 關於 底線 內容
1.注釋文法:--,#
2.尾碼是.sql的檔案是資料庫查詢檔案
3.儲存查詢
4.在資料庫裡面 列有個名字叫欄位 行有個名字叫記錄
CRUD操作:
create 建立(添加)
read 讀取
update 修改
delete 刪除
1、添加資料
insert into Info values(‘p009‘,‘張三‘,1,‘n001‘,‘2016-8-30 12:9:8‘) ;
給特定的列添加資料
insert into Info (code,name) values(‘p010‘,‘李四‘);
自增長列的處理
insert into family values(‘‘,‘p001‘,‘資料‘,‘T001‘,‘資料‘,1);
insert into 表名 values(值)
2、刪除資料
刪除所有資料
delete from family
刪除特定的資料
delete from Info where code=‘p001‘
delete from 表名 where 條件
3、修改資料
修改所有資料
update Info set name=‘徐業鵬‘
修改特定資料
update Info set name=‘呂永樂‘ where code=‘p002‘
修改多列
update Info set name=‘呂永樂‘,sex=1 where code=‘p003‘
update 表名 set 要修改的內容 where 條件 tno =
4、讀取資料
(1)簡單讀取,查詢所有列(*) 所有行(沒有加條件)
select * from Info
(2)讀取特定列
select code,name from Info
(3)條件查詢
select * from Info where code=‘p003‘
(4)多條件查詢
select * from Info where code=‘p003‘ or nation=‘n002‘ #或的關係
select * from Info where sex=0 and nation=‘n002‘ #與的關係
(5)關鍵字查詢(模糊查詢)
查所有包含奧迪的汽車
select * from car where name like ‘%奧迪%‘; #百分比符號%代表任意多個字元
查以‘皇冠‘開頭的所有汽車
select * from car where name like ‘皇冠%‘;
查詢汽車名稱中第二個字元是‘馬‘的
select * from car where name like ‘_馬%‘; #底線_代表任意一個字元
(6)排序查詢
select * from car order by powers #預設升序排列
select * from car order by powers #升序asc 降序 desc
先按brand升序排,再按照price降序排
select * from car order by brand,price desc
(7)範圍查詢
select * from car where price9()>40 and price<60
select * from car where price between 40 and 60
關於mysql增刪改查的基本操作