DML
作用:针对表中数据行进行的增删改查
insert 插入数据
desc st;
------标准
insert into st(id,name,age,gender,address,intime,cardnum,num)
values(1,‘张三’,18,‘m’,‘北京’,‘2020-04-27’,‘123456’,10);
select * from st;
------部分列录入
插入必填信息,时间为系统当前时间now()
desc st;
insert into st(name,intime,num)
values(‘李四’,now(),11);
select * from st;
alert table st modify intime datatime not null default NOW() comment ‘入学时间’;
insert into st(name,num)
value(‘王五’,12);
select * from st;
------省略写法
desc st;
insert into st
value(5,‘张三’,18,‘m’,‘北京’,‘2020-04-27’,‘123456’,10);
select * from st;
updata 更新数据行
update st set name=‘张六’,age=20 where id=4;
select * from st;
delete 删除数据行
delete from st where id=5;
select *from st;
DQL数据查询
-------select 应用
查询数据库服务器配置
select @@port;
select @@server_id;
select @@basedir;
select @@socket;
select @@innodb_flush_log_at_trx_commit;
------替代方法
show variables;
show variables like ‘%trx%’;
-------查询函数
select DATABASE();
select NOW();
select USER();
select CONTACT(“hellow world”);
select user,host from mysql.user;
select CONTACT(user,“@”,host,“;”) from mysl.user;
#其他数据库
select NOW() from dual;
select 通用使用方法
select 多语句执行顺序(单表查询)
select 列 from 表 where 条件 group by 列 having 条件 order by 列 limit 条件
#select 配合from 子句使用
查询表中所有数据
user world;
查看表的定义
desc city;
id 主键 1-N数字
name 城市名
select id,name,countrycode from city;
select * from city where id<10;
-------查询表中所有数据(小表*)
user world;
select id,name from city;
select id,name from world.city;
select * from city;
-------查询部分列数据
select name,population from city;
------select + from + where 子句使用
----where 配合 比较 操作符(= != < >)
eg:查询city中,所有中国信息
select * from city where countrycode = ‘CHN’;
eg:查询人口数小于100人城市信息;
select * from city where population <100;
------- where 配合逻辑连接符(and,or,between,and),实现多条件过滤
eg:查询中国,人口数超过500w的所有城市信息
select * from city where countrycode=‘CHN’ and | population>500000