当前位置:网站首页>【MySQL-表结构与完整性约束的修改(ALTER)】
【MySQL-表结构与完整性约束的修改(ALTER)】
2022-07-06 09:22:00 【馥滢( '▿ ' )】
数据库TestDb1中有表your_table,请根据提示,在右侧代码文件编辑窗中添加恰当的语句,将表名your_table更改为my_table。
USE TestDb1;
#请在以下空白处添加恰当的语句,将表名your_table更改为my_table:
alter table your_table rename to my_table;
假设数据库MyDb中有表order(订单)和orderDetail(订单明细) 等表,两表的结构分别如下:
order表
字段名称 数据类型 备注 orderNo char(12) 订单号,主码 orderDate date 订购日期 customerNo char(12) 客户编号,外码,与customer.customerNo对应 employeeNo char(12) 雇员工号,外码,与employee.employeeNo对应 orderDetail表
字段名称 数据类型 备注 orderNo char(12) 订单号,主属性,外码,与order.orderNo对应 productNo char(12) 产品编号,主属性,外码,与product.productNo对应 quantityOrdered int 订购数量 orderDate date 订购日期 注:表orderDetail的主码由(orderNo,productNo)组成
编程的任务是对orderDetail表进行修改:
- orderDetail表的orderDate列明显多余,因为同一订单中的每一笔交易都发生在同一天,这个日期在订单主体表order中已有记录,请删除列orderDate。
- 产品的单价是订单明细需要记录的内容,请在orderDetail中添加列unitPrice以记录产品的单价:
字段名称 数据类型 备注 unitPrice numeric(10,2) 产品的成交单价 请根据提示,在右侧代码文件编辑窗中添加恰当的语句,实现上述编程任务。
use MyDb;
#请在以下空白处添加适当的SQL代码,实现编程要求
#语句1:删除表orderDetail中的列orderDate
alter table orderDetail drop orderDate;
#语句2:添加列unitPrice
alter table orderDetail add column unitPrice numeric(10,2);
数据库MyDb中有表addressBook(通信录),结构如下:
字段名称 | 数据类型 | 备注 |
---|---|---|
serialNo | int | 自动编号,主码 |
name | char(32) | 姓名 |
company | char(32) | 工作单位 |
position | char(10) | 职位 |
workPhone | char(16) | 办公电话 |
mobile | char(11) | 手机 |
int | QQ号 | |
weixin | char(12) | 微信号 |
当初创建表的语句如下:
create table addressBook(
serialNo int auto_increment primary key,
name char(32),
company char(32),
position char(10),
workPhone char(16),
mobile char(11),
QQ int,
weixin char(12)
);
你的编程任务是对表addressBook作以下修改:
- 将QQ号的数据类型改为char(12);
- 将列名weixin改为wechat。
use MyDb; #请在以下空白处添加适当的SQL语句,实现编程要求 alter table addressBook modify QQ char(12) ; alter table addressBook rename column weixin to wechat;
边栏推荐
- 记一次猫舍由外到内的渗透撞库操作提取-flag
- 1.初识C语言(1)
- Leetcode.3 无重复字符的最长子串——超过100%的解法
- 强化学习系列(一):基本原理和概念
- 力扣152题乘数最大子数组
- 3. Input and output functions (printf, scanf, getchar and putchar)
- 深度强化文献阅读系列(一):Courier routing and assignment for food delivery service using reinforcement learning
- 【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...
- 7-15 h0161. 求最大公约数和最小公倍数(PTA程序设计)
- 【九阳神功】2016复旦大学应用统计真题+解析
猜你喜欢
【手撕代码】单例模式及生产者/消费者模式
ABA问题遇到过吗,详细说以下,如何避免ABA问题
Service ability of Hongmeng harmonyos learning notes to realize cross end communication
1. Preliminary exercises of C language (1)
自定义RPC项目——常见问题及详解(注册中心)
3. Number guessing game
[dark horse morning post] Shanghai Municipal Bureau of supervision responded that Zhong Xue had a high fever and did not melt; Michael admitted that two batches of pure milk were unqualified; Wechat i
Have you encountered ABA problems? Let's talk about the following in detail, how to avoid ABA problems
Leetcode.3 无重复字符的最长子串——超过100%的解法
Mortal immortal cultivation pointer-1
随机推荐
Differences among fianl, finally, and finalize
hashCode()与equals()之间的关系
实验七 常用类的使用(修正帖)
Why use redis
Nuxtjs quick start (nuxt2)
7-9 制作门牌号3.0(PTA程序设计)
C语言入门指南
编写程序,模拟现实生活中的交通信号灯。
The difference between abstract classes and interfaces
7-1 输出2到n之间的全部素数(PTA程序设计)
【毕业季·进击的技术er】再见了,我的学生时代
[modern Chinese history] Chapter 6 test
【九阳神功】2017复旦大学应用统计真题+解析
1. C language matrix addition and subtraction method
受检异常和非受检异常的区别和理解
3. Input and output functions (printf, scanf, getchar and putchar)
稻 城 亚 丁
[the Nine Yang Manual] 2016 Fudan University Applied Statistics real problem + analysis
【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...
Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis