MySql高级查询
来源:互联网 发布:淘宝店铺严重违规12分 编辑:程序博客网 时间:2024/05/17 21:53
1.修改表
修改表名:alter table oldname RENAME newname
添加字段:alter table 表名 add 字段名 数据类型…
修改字段:alter table 表名 CHANGE 原字段名 新字段名 数据类型…
删除字段:alter table 表名 drop 字段名
添加主外键:主键: alter table 表名 add [constraint 主键名] primary key (主键字段)
组合主键:alter table 表名 add [constraint 主键名] primary key (主键字段1,字段2,…)
外键: alter table 表名 add constraint 外键名 foreign key (外键字段) references 主键表名(主键字段)
删除主外键:主键: alter table 表名 drop primary key
外键: alter table 表名 drop foreign key 外键名
2.插入数据
insert into 表名 (字段名列表) values(值列表),(值列表)….
查询语句插入新表:
select 字段,字段… into 新表 from 原表 (要先创建表)
insert into 新表 (字段列表) select 字段,字段… from 原表
create table 新表 (select 字段,字段,… form 原表); 自动创建新表
3.更新数据
update 表名 set 字段=值,字段=值,字段=值,….. (where 条件)
4.删除数据
delete from 表名 (where条件)
删除表中所有行 truncate table 表名
5.LIMIT子句
放在句子最后
LIMIT [位置偏移量,][行数] 例:limit 4,4 从数据第5条开始读取5个数据
6.常用函数
AVG()平均值 count()行数 max()最大值 min()最小值 sum()字段的和
NOW()获取当前时间 YEAR()获取年
7.子查询
select 字段,字段… form 表1 where 字段 比较运算符 (子查询);
IN(NOT IN)
select 字段,字段… form 表 where (not) exists (子查询)
select (子查询),字段 from 表
- MYSQL之高级查询
- mysql高级查询
- Mysql高级查询
- mysql高级查询
- mysql中的高级查询
- mysql高级数据查询
- 【Mysql】高级查询
- MySQL高级查询
- MySql高级查询
- mysql高级查询
- MySql高级查询语句
- MySQL 高级查询
- MySql高级查询
- MYSQL高级查询
- MySql高级查询
- mysql高级排序&高级匹配查询示例
- mysql高级查询技巧一二
- MySql高级查询(1)
- SSD: Single Shot MultiBox Detector 模型fine-tune和网络架构
- ubuntu彻底删除mysql 然后 手动安装mysql 压缩后的二进制包
- map容器安插的方式
- 【算法题】最长公共子序列
- 2017年6月30日,周结(十九),大三期末总结(二)
- MySql高级查询
- Leetcode--136.Single Number
- std::map用法
- Stateless functional component 和 shouldComponentUpdate
- 算法笔记--逆元
- 1072: [SCOI2007]排列perm
- css定位的使用方法
- github 创建远程分支以及远程分支无法删除的问题解决
- Windows下elasticsearch安装jieba分词插件