Home > Database > Mysql Tutorial > body text

MySQL common syntax

正念的奇迹
Release: 2017-08-08 16:52:49
Original
1258 people have browsed it

Show which databases there are: show databases;

Create database: create database database1;

Delete database: drop database database1;

Use database: use database1;

View the table: show tables;

Create a new table: create table table1(

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

a varchar (20),

b int(10),

c varchar(10) default 'Male',

d int(10)

) ;

View table structure: desc student;

Delete table: drop table student;

Delete primary key: alter table table1 drop primary key;

Add primary key: alter table table1 add primary key(id);

Delete field:alter table table1 drop classid;

Add field:alter table table1 add classid int(10);

Add records: insert into table1(a,b,c,d) values('haha',1,'Hello',2);

Delete: delete from table1 where b = 1;

Modify: update table1 set a = 'hahaha' where b=1;

Wildcard %: multiple arbitrary characters_: one Characters

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

Query:

select * from table1;

select id,name from table1;

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

Sort default ascending order asc descending order desc

select * from table1 order by a asc;

select * from table1 order by a desc;

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

Group function min max count avg

select count(*) from table1;

select min(a) from table1;

select avg(a) from table1;

select max(a ) from table1;

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

words as query conditions: select * from table1 where age = (select min(b) from table1);


The above is the detailed content of MySQL common syntax. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template