当前位置:网站首页>【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;
边栏推荐
- Redis实现分布式锁原理详解
- 7-7 7003 组合锁(PTA程序设计)
- 7-8 7104 约瑟夫问题(PTA程序设计)
- Record a penetration of the cat shed from outside to inside. Library operation extraction flag
- 7-15 h0161. 求最大公约数和最小公倍数(PTA程序设计)
- Reinforcement learning series (I): basic principles and concepts
- 甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
- 2022 Teddy cup data mining challenge question C idea and post game summary
- Change vs theme and set background picture
- Mortal immortal cultivation pointer-1
猜你喜欢

Wei Pai: the product is applauded, but why is the sales volume still frustrated

扑克牌游戏程序——人机对抗

仿牛客技术博客项目常见问题及解答(一)

Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis

C language Getting Started Guide

受检异常和非受检异常的区别和理解

5. Function recursion exercise

fianl、finally、finalize三者的区别

C language to achieve mine sweeping game (full version)

The latest tank battle 2022 - Notes on the whole development -2
随机推荐
重载和重写的区别
仿牛客技术博客项目常见问题及解答(三)
1. C language matrix addition and subtraction method
It's never too late to start. The tramp transformation programmer has an annual salary of more than 700000 yuan
【九阳神功】2018复旦大学应用统计真题+解析
深度强化文献阅读系列(一):Courier routing and assignment for food delivery service using reinforcement learning
Implementation of count (*) in MySQL
渗透测试学习与实战阶段分析
TypeScript快速入门
js判断对象是否是数组的几种方式
撲克牌遊戲程序——人機對抗
附加简化版示例数据库到SqlServer数据库实例中
7-5 走楼梯升级版(PTA程序设计)
7-6 矩阵的局部极小值(PTA程序设计)
The difference between cookies and sessions
[中国近代史] 第六章测验
Redis的两种持久化机制RDB和AOF的原理和优缺点
FAQs and answers to the imitation Niuke technology blog project (III)
优先队列PriorityQueue (大根堆/小根堆/TopK问题)
MySQL事务及实现原理全面总结,再也不用担心面试