首頁  >  文章  >  資料庫  >  MySQL常用文法

MySQL常用文法

正念的奇迹
正念的奇迹原創
2017-08-08 16:52:491199瀏覽

顯示有哪些資料庫:show databases;

建立資料庫:create database database1;

刪除資料庫:drop database database1;

#使用資料庫: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)

#) ;

查看表格結構: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;

通配符%:多個任意的字元_:一個字元

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

查詢:

##select * from table1;

select id,name from table1;

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

排序預設升序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;

群組函數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常用文法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn