您的位置:首页 > 数据库 > MySQL

MySQL语句(部分常用例句)

2017-08-08 13:51 316 查看
使用MySQL

cmd指令

d:

cd D:\mysql5\bin;

mysql -uroot -pmysql;

MySQL语句

1.创建数据库

create database dbName;//dbName 数据库名


2.显示已有数据库

show databases;


3.删除数据库

drop database dbName;


4.使用数据库

use dbName;


5.创建表

create table tName(columName1 type1 state1,columName2 type2,columName3 type3);
//tName 表名,columnName1 字段名,type1 字段数据类型,state1数据限制或属性


6.显示已有表

show tables;


7.删除表

drop table tName;


8.对表增加一列

alter table tName add columName1 type1 state1;


9.对表删除一列

alter table tName drop columName1;


10.对表查询

select * from tName  where 条件;


11.对表插入一行

insert into tName(columName1,columName2) values(value1,value2);


12.对表删除

delete from t
4000
Name where 条件;


13.对表更新

update tName set columName1 = 'value1' where 条件;


函数使用

count统计:select count(条件) from tName where 条件;//一般使用 count(*)
sum求和:select sum(条件) from tName;
【注】count和sum的区别:count用于统计多少行满足条件,sum用户统计满足条件所查值得算数和

avg求平均值:select avg(条件) from tName;//对sum后的值进行求平均
max最大值:select max(条件) from tName;
min最小值:select min(条件) from tName;

group by分组查询:select * from tName group by columName1;
asc升序排列(默认):select * from tName order by id asc;
desc降序排列:select * from tName order by id desc;
limit分页限制:select * from tName order by id limit start,total;
【注】start是分页的起始位置(默认是0); total是显示的行数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: