Mysql各种

    科技2023-12-20  89

    mysql的增删查改

    插入 insert 表名 values (0,'jack'); 多行插入 insert 表名 (id,name) values(0,'jack'),(1,'rose'); 查询 select * from 表名; 显示表的所有内容 select 条件 from 表名; 显示条件列 指定条件查询 select * from 表名 where age>13 筛选表中age>13的内容 select * from 表名 where name like %王% 查询名字中有wang的人 可以使用as给列或表指定别名 select name as 'mingzi' from ss; 吧name列以'mingzi'列显示出来 改 update 表名 set age=1 where name=jack; 把name=jack的age改成1 update 表名 set age=age+1 表中所有人的age+1 删除 delete from 表名 where id=1 删除id是1的行 delete from 表名 ; 删除表中的所有的内容 表结构的修改 alter table 表名 add birthday(添加的字段) datetime(类型) after age(字段); 在age后插入birthday字段 alter table 表名 drop 列名; 删除字段 alter table 表名 modify birthday date; 更改字段类型 alter table 表名 change 原名 新名 类型 ; 更改字段的名称 表格重命名 alter table 表名 rename 新名; 或 rename table 表名 to 新名;

    聚合函数

    select count(*) from list_name where sex='man'; 统计man的人数 select max(age) from list_name; 查询年龄最大的 select min(age) from list_name; 查询最小age select sum(age) from list_name; 查询age的和 select avg(age) from list_name; 查询age的平均数 select * from list_name order by age asc; age从小到大排序 select * from list_name order by age desc; age从大到小排排序 show engines; 查看存储引擎

    范围查询

    select * from list_name where age in (18,34); 查询年龄是18,34的内容 select * from list_name where age not in (18.34); 查询年龄不是18 34 的内容 select * from list_name where age between 18 and 34; 年龄在18-34之间的内容 select *from list_name where age not between 18 and 34; 年龄不在18-34之间的内容

    表的复制

    create table new_listname like old_listname; 复制表结构 create table new_listname as select * from old_listname; 复制表的数据

    创建视图

    create view v_listname as select * from listname 创建视图 drop v_listname 删除视图 视图的作用:1 防止未经许可的用户访问敏感数据 2封装sql语句简化查询过程 3屏蔽真实的表结构
    Processed: 0.010, SQL: 8