Home > Database > Mysql Tutorial > Understand the basic syntax of mysql

Understand the basic syntax of mysql

迷茫
Release: 2017-03-26 13:07:40
Original
1342 people have browsed it

Create table

create table <表名>(
 <字段名>  类型(长度) not null primary key auto_increment, **主键
 name char(20) not null,  
 sex int(4) not null default &#39;0&#39;, **默认键
 degree double(16,2)
)
Copy after login

Delete table

drop table <表名>;
//情空表
delete from <表名>;
Copy after login

Insert data

insert into <表名> [( <字段名1>[,..<字段名n > ])] values ( 值1 )[, ( 值n )]
Copy after login

Query table

select <字段1,字段2,...> from < 表名 > where < 表达式 >
Copy after login

Query the first few fields of the table

select * from MyClass order by id limit 0,2;
Copy after login

Query field sum

select sum('field name') from table name

Query fields are arranged in ascending order and descending order

Descending order:select * from table name where expression order by field name desc

ascending order:select * from table name where Putout=true order by time asc

delete table

delete from 表名 where 表达式
Copy after login

modify table

update 表名 set 字段=新值,… where 条件
Copy after login

Add table fields

alter table table name add field type other;

<1 Primary key:alter table table name add primary key (field name);

<2 Unique constraints: alter table table name add unique index name (field name);

Delete table field

alter table 表名 drop 字段名
Copy after login

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

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template