当前位置:网站首页>【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;
边栏推荐
- 【VMware异常问题】问题分析&解决办法
- [hand tearing code] single case mode and producer / consumer mode
- 9. Pointer (upper)
- 5. Download and use of MSDN
- Principles, advantages and disadvantages of two persistence mechanisms RDB and AOF of redis
- Nuxtjs快速上手(Nuxt2)
- 透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
- Reinforcement learning series (I): basic principles and concepts
- This time, thoroughly understand the MySQL index
- 7-5 走楼梯升级版(PTA程序设计)
猜你喜欢
实验六 继承和多态
透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
Differences among fianl, finally, and finalize
[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
The difference between cookies and sessions
. Net6: develop modern 3D industrial software based on WPF (2)
(original) make an electronic clock with LCD1602 display to display the current time on the LCD. The display format is "hour: minute: Second: second". There are four function keys K1 ~ K4, and the fun
QT meta object qmetaobject indexofslot and other functions to obtain class methods attention
2022泰迪杯数据挖掘挑战赛C题思路及赛后总结
仿牛客技术博客项目常见问题及解答(一)
随机推荐
js判断对象是否是数组的几种方式
[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
简单理解ES6的Promise
Leetcode.3 无重复字符的最长子串——超过100%的解法
实验七 常用类的使用
Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis
Get started with typescript
[modern Chinese history] Chapter V test
4. Branch statements and loop statements
【手撕代码】单例模式及生产者/消费者模式
一段用蜂鸣器编的音乐(成都)
QT meta object qmetaobject indexofslot and other functions to obtain class methods attention
受检异常和非受检异常的区别和理解
The latest tank battle 2022 full development notes-1
抽象类和接口的区别
渗透测试学习与实战阶段分析
4.分支语句和循环语句
7-9 制作门牌号3.0(PTA程序设计)
[during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
[graduation season · advanced technology Er] goodbye, my student days