Python全栈 MySQL 数据库 (SQL查询、备份、恢复、授权)
开局一张图
综合性练习:
综述:两张表,一张顾客信息表customers,一张订单表orders
1、创建一张顾客信息表customers,字段要求如下:
c_id 类型为整型,设置为主键,并设置为自增长属性
c_name 字符类型,变长,宽度为20
c_age 微小整型,取值范围为0~255(无符号)
c_sex 枚举类型,要求只能在('M','F')中选择一个值
c_city 字符类型,变长,宽度为20
c_salary 浮点类型,要求整数部分最大为10位,小数部分为2位
在表中任意插入3条记录,c_name为"Zhangsan","Lisi","Wangwu", c_city尽量 写"Beijing","Shanghai" ......
insert into customers values
(1,"Zhangsan",25,"M","Beijing",8000),
(2,"Lisi",30,"F","Shanghai",10000),
(3,"Wangwu",27,"M","Shenzhen",3000);
2、创建一张订单表orders,字段要求如下:
o_id 整型
o_name 字符类型,变长,宽度为30
o_price 浮点类型,整数最大为10位,小数部分为2位
设置此表中的o_id字段为customers表中c_id字段的外键,更新删除同步
在表中任意插入5条记录(注意外键限制)
o_name分别为"iphone","ipad","iwatch","mate9","r11",其他信息自己定
insert into orders values
(1,"iphone",5288),
(1,"ipad",3299),
(3,"mate9",3688),
(2,"iwatch",2222),
(2,"r11",4400);
3、返回customers表中,工资大于4000元,或者年龄小于29岁,满足这样条件的前2条记录
4、把customers表中,年龄大于等于25岁,并且地址是北京或者上海,这样的人的工资上调15%
5、把customers表中,城市为北京的顾客,按照工资降序排列,并且只返回结果中的第一条记录
6、选择工资c_salary最少的顾客的信息
7、找到工资大于5000的顾客都买过哪些产品的记录明细
8、删除外键限制
9、删除customers主键限制
1、删除自增长属性
2、删除主键限制
综述:两张表,一张顾客信息表customers,一张订单表orders
1、创建一张顾客信息表customers,字段要求如下:
c_id 类型为整型,设置为主键,并设置为自增长属性
c_name 字符类型,变长,宽度为20
c_age 微小整型,取值范围为0~255(无符号)
c_sex 枚举类型,要求只能在('M','F')中选择一个值
c_city 字符类型,变长,宽度为20
c_salary 浮点类型,要求整数部分最大为10位,小数部分为2位
create table customers(
c_id int primary key auto_increment,
c_name varchar(20),
c_age tinyint unsigned,
c_sex enum("M","F"),
c_city varchar(20),
c_salary float(12,2)
); 在表中任意插入3条记录,c_name为"Zhangsan","Lisi","Wangwu", c_city尽量 写"Beijing","Shanghai" ...... insert into customers values
(1,"Zhangsan",25,"M","Beijing",8000),
(2,"Lisi",30,"F","Shanghai",10000),
(3,"Wangwu",27,"M","Shenzhen",3000); 2、创建一张订单表orders,字段要求如下:
o_id 整型
o_name 字符类型,变长,宽度为30
o_price 浮点类型,整数最大为10位,小数部分为2位
设置此表中的o_id字段为customers表中c_id字段的外键,更新删除同步
create table orders(
o_id int,
o_name varchar(30),
o_price float(12,2),
foreign key(o_id) references customers(c_id)
on delete cascade
on update cascade
);
在表中任意插入5条记录(注意外键限制)
o_name分别为"iphone","ipad","iwatch","mate9","r11",其他信息自己定
insert into orders values
(1,"iphone",5288),
(1,"ipad",3299),
(3,"mate9",3688),
(2,"iwatch",2222),
(2,"r11",4400); 3、返回customers表中,工资大于4000元,或者年龄小于29岁,满足这样条件的前2条记录
select * from customers where c_salary > 4000 or c_age < 29 limit 2; 4、把customers表中,年龄大于等于25岁,并且地址是北京或者上海,这样的人的工资上调15%
update customers set c_salary=c_salary*1.15 where c_age >= 25 and c_city in ("Beijing","Shanghai"); 5、把customers表中,城市为北京的顾客,按照工资降序排列,并且只返回结果中的第一条记录
select * from customers where c_city="Beijing" order by c_salary desc limit 1; 6、选择工资c_salary最少的顾客的信息
select * from customers
where c_salary = (select min(c_salary) from customers); 7、找到工资大于5000的顾客都买过哪些产品的记录明细
select * from orders where o_id in (select c_id from customers where c_salary > 5000); 8、删除外键限制
1、show create table orders;
2、alter table orders drop foreign key orders_ibfk_1; 9、删除customers主键限制
1、删除自增长属性
alter table customers modify c_id int;
2、删除主键限制
alter table customers drop primary key;
10、增加customers主键限制c_id
alter table customers add primary key(c_id);
Python全栈 MySQL 数据库 (SQL查询、备份、恢复、授权)的更多相关文章
- Python全栈 MySQL 数据库(SQL命令大全、MySQL 、Python调用)
为了梦想与了信仰 开局一张图 主要三个方面: 1.Linux终端命令 2.MySQL语句 3.Python调用 先删库 再跑路..... ...
- Python全栈 MySQL 数据库 (引擎、事物、pymysql模块、orm)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 存储引擎(处理表的处理器) 基本操作: ...
- Python全栈 MySQL 数据库 (简述 、安装、基本命令)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 一个月的python已经结束了 下面就是数据库了 先说M ...
- Python全栈 MySQL 数据库 (索引、数据导入、导出)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 表字段重命名(change) alter table 表名 ...
- Python全栈 MySQL 数据库 (表字段增、删、改、查、函数)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 查询SQL变量 show variables 1.表字 ...
- 巨蟒python全栈开发数据库攻略3:行记录的操作&单表查询3
1.数据行的增删改 2.单表查询 select&where条件 3.group by&having&order by&limit
- Python全栈 MongoDB 数据库(概念、安装、创建数据)
什么是关系型数据库? 是建立在关系数据库模型基础上的数据库,借助于集合代数等概念和方法来处理数据库中的数据, 同时也是一个被组织成一组拥有正式描述性的表格( ...
- MySql数据库 sql查询增加序号的伪列
在查询数据库的时候,我们有时候需要对查询出来的数据加上序列,1,2,3,……n 例如:我们根据表的某个字段排序后,要对这些数据加上序列,这个时候序号常常不是我们建表时设置好的自增的主键id,怎么办呢? ...
- 巨蟒python全栈开发数据库前端6:事件onclick的两种绑定方式&&onblur和onfocus事件&&window.onload解释&&小米商城讲解
1.回顾上节内容(JavaScript) 一.JavaScript概述 1.ECMAScript和JavaScript的关系 2.ECMAScript的历史 3.JavaScript是一门前后端都可以 ...
随机推荐
- An error occurred at line: 1 in the generated java file问题处理
tomcat6启动后,加载jsp页面报错,提示无法将jsp编译为class文件,主要报错信息如下: An error occurred at line: 1 in the generated java ...
- HTML5<fieldset>标签
1.<fieldset>标签对表单中的相关元素进行分组. 2.<fieldset>标签会在相关表单元素周围绘制边框. <!DOCTYPE html><html ...
- c++ 11 线程池的简单封装
#include <condition_variable> #include <queue> #include <thread> #include <vect ...
- Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 36
例: <aop:config> <aop:pointcut expression="execution(* com.zsn.Service.Impl.*.*(..))&qu ...
- 基于mybatis设计简单信息管理系统2
1.空指针异常 public class CanvasServlet extends HttpServlet { private CanvasService canvasService; privat ...
- 【转载】java 客户端链接不上redis解决方案 (jedis)
本文出自:http://blog.csdn.net/lulidaitian/article/details/51946169 出现问题描述: 1.Could not get a resource fr ...
- 02 mysql 基础二 (进阶)
mysql 基础二 阶段一 表约束 1.not null 非空约束 例子: create table tb1( id int, name varchar(20) not null ); 注意 空字符不 ...
- PAT (Basic Level) Practice 1021 个位数统计
个人练习 给定一个 k 位整数 N=dk−110k−1+⋯+d1101+d0 (0≤di≤9, i=0,⋯,k−1, dk−1>0),请编写程序统计每种 ...
- 牛客暑假多校第二场J-farm
一.题意 White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. T ...
- Diycode开源项目 如何解决InputMethodManager造成的内存泄漏问题
1.内存泄漏的状况及原因 1.1.利用LeakCanary查看内存泄漏的状况 1.2.内存泄漏怎么产生的呢? InputMethodManager.mServicedView持有一个最后聚焦View的 ...