1、SQL分类:
sql的功能很强大可以分为以下几组:
DML:数据操作语言---检索或修改数据;
DDL:数据定义语言---定义数据库的结构,如创建、修改、删除数据库对象;
DCL:数据控制语言---定义数据库用户的权限
2、主要用DDL对数据库数据操作:(增删改查)
mysql -uroot -p123 -----首先连接数据库服务;
use lid ----使用的是lid这个数据库;
DROP table user; ---删除数据库表;
create table user(
id int auto_increment primary key ,
name varchar(30) not null ,
password varchar(32) not null ,
age int not null ,
sex varchar(2) default '男' ,
birthday Date
);
//添加数据
insert into user(name,password,age,sex,birthday) values('lid','123',20,'男','1986-02-12');
insert into user(name,password,age,sex,birthday) values('yuj','456',20,'nv','1986-02-13');
id是自动编号,所以回从1开始自增;
//删除数据
delete from user where sex='nv';
//更新数据:
update user set age='19' where name='yuj';
//查询数据:
简单查询:
限定查询:
多表查询:
分组统计:
子查询:
交、并、补:
select * from user;
select name,age from user;
select * from user where name like '%l%' or name like '%u%';
select * from user where name like '%l%' or name like '%u%' limit 0,5;----部分查询,实现分页;
select * from user limit 0,5;----0表示从哪一个开始,5表示查几条;