MySQL常用語法
發表時間:2023-07-23 來源:明輝站整理相關軟件相關文章人氣:
[摘要]顯示有哪些數據庫:show databases;創建數據庫:create database database1;刪除數據庫:drop database database1;使用數據庫:use dat...
顯示有哪些數據庫: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中文網其它相關文章!
學習教程快速掌握從入門到精通的SQL知識。