mysql操作命令有哪些

這篇文章主要介紹MySQL操作命令有哪些,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的紅古網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

//創(chuàng)建數(shù)據(jù)庫create database school;

//創(chuàng)建表
create table info (id int not null primary key auto_increment,name char(10) not

null,score decimal(5,2),hobby int(2));
#primary key 主鍵 auto_increment 自增列 
//查看表結(jié)構(gòu)
desc info;
//多表查詢(關(guān)聯(lián)表)
select * from info inner join hob where info.hobby=hob.id;

select info.name,score,hob.hobname from info inner join hob where

info.hobby=hob.id;
//別名查詢
select i.name,score,h.hobby from info as i inner join hob as h where i.hobby=h.id;

//聚合函數(shù)
統(tǒng)計(jì)count(): 可以改為1
select count(
) from info;
平均值avg ()
select avg(score) from info;
//查看數(shù)據(jù)庫
show databases;
//進(jìn)入數(shù)據(jù)庫
use myschool;
//查看myschool中的表
show tables;
//查看info中的數(shù)據(jù)
select from info;
//在info中插入數(shù)據(jù)
insert into info (id,name,score) values ('tianqi',55); #前后匹配,如果為空:null
//篩選信息
mysql> select 
from 表名 where id=2[and name=?] [or name=?]
//更新信息
update info set score=75 where id=6;
//刪除信息
delete from info where name='test'; #整行刪除
//刪除表、數(shù)據(jù)庫
drop table info; drop database school;
//排序
select from info where 1=1 order by score ; asc--升序,可不寫 #默認(rèn)升序
select 
from info where 1=1 order by score desc ; desc--降序

數(shù)據(jù)庫索引、事務(wù)、視圖

索引:快速查詢數(shù)據(jù)  條件:數(shù)據(jù)數(shù)目大于兩千條 
相當(dāng)于一本書前的目錄頁

create index 索引名稱 on tablename 列;
id name score address hobby

create index id_index on info(id); 創(chuàng)建普通索引

show index from info \G; 查看索引折行顯示

drop index id_index on info; 刪除索引

create unique index id_index on info(id); 創(chuàng)建唯一索引

alter table info add primary key(id); 主鍵索引

alter table info add column age int(3); 添加列

alter table info drop column age; 刪除列

create table infos (descript TEXT,FULLTEXT(descript));全文索引,descript列名描述

create index multi_index on info(name,address); 多頁索引,講兩個(gè)條件聯(lián)合起來進(jìn)行

查詢

事務(wù):一組操作共同執(zhí)行或者都不執(zhí)行,結(jié)果保持一致

舉個(gè)栗子:銀行轉(zhuǎn)賬
條件:轉(zhuǎn)賬條件余額大于0
姓名 余額
張三 100
李四 200

張三轉(zhuǎn)賬100 to 李四

begin 開始

updata bank set money=money-100 where name='zhangsan'

updata bank set money=money+100 where name='lisi'

commit 提交

savepoint s1; 設(shè)定回滾點(diǎn)

rollback to savepoint s1; 回到s1回滾點(diǎn)

set autocommit=0 禁止自動(dòng)提交
set autocommit=1 開啟自動(dòng)提交
rollback 回滾

原子性 不可分割

一致性 前后結(jié)果保持一致

隔離性 事務(wù)之間隔離,互不影響

持久性 一旦執(zhí)行成功,不可更改

視圖      數(shù)據(jù)庫中的虛擬表

作用:一張表或者多張表中的數(shù)據(jù)給不同的權(quán)限用戶提供訪問

create view 視圖名稱 AS

select 語句

select * from info where score > 80; 查看大于80分的人

create view score_view as select * from info where score >80; 形成視圖進(jìn)行查看

select * from score_view; 查看視圖

以上是“mysql操作命令有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文標(biāo)題:mysql操作命令有哪些
URL網(wǎng)址:http://muchs.cn/article0/ippsoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、云服務(wù)器定制開發(fā)、全網(wǎng)營銷推廣ChatGPT、網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)