明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

MySQL常用語法

[摘要]顯示有哪些數(shù)據(jù)庫(kù):show databases;創(chuàng)建數(shù)據(jù)庫(kù):create database database1;刪除數(shù)據(jù)庫(kù):drop database database1;使用數(shù)據(jù)庫(kù):use dat...
顯示有哪些數(shù)據(jù)庫(kù):show databases;

創(chuàng)建數(shù)據(jù)庫(kù):create database database1;

刪除數(shù)據(jù)庫(kù):drop database database1;

使用數(shù)據(jù)庫(kù):use database1;

查看表:show tables;

新建表:create table table1(

id int(10) not null primary key auto increment ,

a varchar(20),

b int(10),

c varchar(10) default '男',

d int(10)

);

查看表結(jié)構(gòu):desc student;

刪除表:drop table student;

刪除主鍵:alter table table1 drop primary key;

增加主鍵:alter table table1 add primary key(id);

刪除字段:alter table table1 drop classid;

增加字段:alter table table1 add classid int(10);

增加記錄:insert into table1(a,b,c,d) values('哈哈',1,'你好',2);

刪除:delete from table1 where b = 1;

修改:update table1 set a = '哈哈哈' where b=1;

通配符 %:多個(gè)任意的字符 _:一個(gè)字符

update table1 set b = 2 where name like '%i%';

查詢:

select * from table1;

select id,name from table1;

select * from table1 where b like '%i%';

排序 默認(rèn)升序asc 降序desc

select * from table1 order by a asc;

select * from table1 order by a desc;

select * from table1 order by a desc,b asc;

組函數(shù) min max count avg

select count(*) from table1;

select min(a) from table1;

select avg(a) from table1;

select max(a) from table1;

分組:select classid,avg(b) from table1 group by classid having avg(b)>5;

字句作為查詢的條件:select * from table1 where age = (select min(b) from table1);

以上就是MySQL常用語法的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!


學(xué)習(xí)教程快速掌握從入門到精通的SQL知識(shí)。




標(biāo)簽:MySQL常用語法