您的位置:首页 > 数据库

SQL语句基本操作

2014-05-20 15:40 253 查看
数据库工具 sql yog(中文版) Navicat Premium(英文版)

mysql数据库-->Database(数据库)-->table(数库表)-->field(字段)

增加---insert into table(字段名)values(值);

删除---delete from table where id='字段名';

修改---update table set name='字段名' where id=1;

查询---select */整张表 from table/表名 select id=1/单个查询, name/字段
名 from table/表名;

删除数据库---drop database;

show database;//查询所有数据库

create database studnt;//创建数据库
use student;//使用数据库

create table stu(id int not null primary key AUTO_INCREMENT,name

varchar(50))
age varchar(100);//创建表

insert into stu(id,name,age)values(1,'长沙源码','10');//增加

select * from stu;//查询全部

insert into stu(id,name,age) values(2,'中南大学','90'),(3,'湖南大

学','100');增加

select * from stu;//查询全部

select count(*) from table;//查询数据条数

select max(id) from stu;//查询最大值 (只能是int型)

select min(id) from stu;//查询最小值 (只能是int型)

select * from stu where id=(select max(id) from stu);//子查询

select * from stu order by id desc;//降序

select * from stu order by(排序) id asc;//升序

select * from stu limit 0,2;//如果是从0开始 取小于2

select * from stu limit 1,2;//从1开始 取2条

select * from stu where stuaddress like '% %'//模糊查询

charset=uf8;//更改编码

select sum(id) as (id号) from table;//查询总和

select * from table group by id;//分组

drop table id//删除表格

having与where类似,可筛选

where ->group by ->having->order ->limit 先后顺序

where 条件查询

group by 分组

having 筛选

order by 排序

limit 限制条数

in //去掉指定条数 between //去多少之多少之间

文章,新闻等安全性要求不高的 选myisam

订单,资金,涉及金额的 选innodb

alter table add primary key //增加主键索引

alter table add unique //增加唯一索引

alter table drop primary key // 删除主键索引

alter table drop index 索引名
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: