Mysql基础语法

Mysql数据库三种基本操作:

DDL--数据定义语言(create,alter,drop,declare)

DML--数据操纵语言(select,delete,update,insert)

DCL--数据控制语言(grant,revoke,commit,rollback)

Mysql基础语句

1、创建数据库

create database database_name

2、删除数据库

drop database database_name

3、备份数据库


4、创建新表

create table tabname(col1 type [not null][primary key],col2 type [not null],...)

5、删除表

drop table tabname

6、增加列

alter table tabname add column col type

7、添加主键

alter table tabname add primary key(col)

8、删除主键

alter table tabname drop primary key(col)

9、添加索引

create [uniqe] index idxname on tabname(col)

10、删除索引

drop index idxname

注:索引时不可更改的,需要更改必须删除重新建

11、创建视图

create view viewname as select statement

12、删除视图

drop view viewname


几个简单基本的sql语句

查找:select * from tabname where condition

插入:insert into tabname(col1,col2) values(value1,value2)

删除:delete from tabname where condition

更新:update tabname set col1=value1 where condition

排序:select * from tabname order by col1[desc/insc]

总数:select count as totalcount from tabname

求和:select sum(col1) as sumvalue from tabname

平均:select avg(col1) as avgvaule from tabname

最大:select max(col1) as maxvalue from tabname

最小:select min(col1) as minvalue from tabname


几个高级查询运算符

UNION运算符

组合两个结果表并消去任何一个重复行而派生出一个结果表,当

EXCEPT运算符

INTERSECT运算符

Mysql基础语法,布布扣,bubuko.com

Mysql基础语法

上一篇:重大发现Discuz DB层跨库映射关系表名前缀BUG


下一篇:(MYSQL)ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)