Home  >  Article  >  Database  >  Understand the basic syntax of mysql

Understand the basic syntax of mysql

迷茫
迷茫Original
2017-03-26 13:07:401270browse

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)
)

Delete table

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

Insert data

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

Query table

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

Query the first few fields of the table

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

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 表达式

modify table

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

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 字段名

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!

Statement:
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