關於mysql增刪改查的基本操作

來源:互聯網
上載者:User

標籤: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增刪改查的基本操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.