当前位置:网站首页>【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;
边栏推荐
- FAQs and answers to the imitation Niuke technology blog project (I)
- [graduation season · advanced technology Er] goodbye, my student days
- 自定义RPC项目——常见问题及详解(注册中心)
- Using qcommonstyle to draw custom form parts
- 【VMware异常问题】问题分析&解决办法
- 2. Preliminary exercises of C language (2)
- 6. Function recursion
- 1. Preliminary exercises of C language (1)
- 5. Function recursion exercise
- 【数据库 三大范式】一看就懂
猜你喜欢

Nuxtjs快速上手(Nuxt2)

MySQL锁总结(全面简洁 + 图文详解)

3. Number guessing game

记一次猫舍由外到内的渗透撞库操作提取-flag

3.输入和输出函数(printf、scanf、getchar和putchar)

1. Preliminary exercises of C language (1)

Read only error handling
![[hand tearing code] single case mode and producer / consumer mode](/img/b3/243843baaf0d16edeab09142b4ac09.png)
[hand tearing code] single case mode and producer / consumer mode

2. First knowledge of C language (2)

1. C language matrix addition and subtraction method
随机推荐
A piece of music composed by buzzer (Chengdu)
【毕业季·进击的技术er】再见了,我的学生时代
实验八 异常处理
【头歌educoder数据表中数据的插入、修改和删除】
C language Getting Started Guide
[面试时]——我如何讲清楚TCP实现可靠传输的机制
力扣152题乘数最大子数组
【九阳神功】2020复旦大学应用统计真题+解析
It's never too late to start. The tramp transformation programmer has an annual salary of more than 700000 yuan
实验九 输入输出流(节选)
Nuxtjs quick start (nuxt2)
【九阳神功】2017复旦大学应用统计真题+解析
Brief introduction to XHR - basic use of XHR
.Xmind文件如何上传金山文档共享在线编辑?
7-1 输出2到n之间的全部素数(PTA程序设计)
MySQL lock summary (comprehensive and concise + graphic explanation)
[during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
Beautified table style
FAQs and answers to the imitation Niuke technology blog project (III)
Custom RPC project - frequently asked questions and explanations (Registration Center)