当前位置:网站首页>[MySQL table structure and integrity constraint modification (Alter)]
[MySQL table structure and integrity constraint modification (Alter)]
2022-07-06 13:53:00 【Fu Ying ('▿')】
database TestDb1 There's a table in it your_table, Please follow the instructions , Add appropriate statements in the code file editing window on the right , Table name your_table Change to my_table.
USE TestDb1;
# Please add the appropriate statement in the space below , Table name your_table Change to my_table:
alter table your_table rename to my_table;
Suppose the database MyDb There's a table in it order( Order ) and orderDetail( The order details ) Isometer , The structures of the two tables are as follows: :
order surface
Field name data type remarks orderNo char(12) The order number , Main code orderDate date subscription date customerNo char(12) Customer number , Outer code , And customer.customerNo Corresponding employeeNo char(12) Employee number , Outer code , And employee.employeeNo Corresponding orderDetail surface
Field name data type remarks orderNo char(12) The order number , Main attribute , Outer code , And order.orderNo Corresponding productNo char(12) Product number , Main attribute , Outer code , And product.productNo Corresponding quantityOrdered int Order quantity orderDate date subscription date notes : surface orderDetail The main code of is (orderNo,productNo) form
The task of programming is to orderDetail Table to be modified :
- orderDetail Tabular orderDate The column is obviously redundant , Because every transaction in the same order occurs on the same day , This date is in the order body table order There are records in , Please delete the column orderDate.
- The unit price of the product is the content that needs to be recorded in the order details , Please be there. orderDetail Add columns unitPrice To record the unit price of the product :
Field name data type remarks unitPrice numeric(10,2) The transaction unit price of the product Please follow the instructions , Add appropriate statements in the code file editing window on the right , Realize the above programming tasks .
use MyDb;
# Please add the appropriate SQL Code , Implement programming requirements
# sentence 1: Delete table orderDetail Column in orderDate
alter table orderDetail drop orderDate;
# sentence 2: Add columns unitPrice
alter table orderDetail add column unitPrice numeric(10,2);
database MyDb There's a table in it addressBook( Address book ), The structure is as follows :
Field name | data type | remarks |
---|---|---|
serialNo | int | auto number , Main code |
name | char(32) | full name |
company | char(32) | Work unit |
position | char(10) | Position |
workPhone | char(16) | Office phone |
mobile | char(11) | mobile phone |
int | QQ Number | |
weixin | char(12) | WeChat ID |
The original statement to create the table is as follows :
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)
);
Your programming task is to check the table addressBook Make the following modifications :
- take QQ The data type of No. is changed to char(12);
- Will be listed weixin Change it to wechat.
use MyDb; # Please add the appropriate SQL sentence , Implement programming requirements alter table addressBook modify QQ char(12) ; alter table addressBook rename column weixin to wechat;
边栏推荐
- Simply understand the promise of ES6
- 7-3 构造散列表(PTA程序设计)
- String abc = new String(“abc“),到底创建了几个对象
- 附加简化版示例数据库到SqlServer数据库实例中
- 关于双亲委派机制和类加载的过程
- [the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
- Leetcode.3 无重复字符的最长子串——超过100%的解法
- 简单理解ES6的Promise
- MySQL事务及实现原理全面总结,再也不用担心面试
- Strengthen basic learning records
猜你喜欢
Reinforcement learning series (I): basic principles and concepts
.Xmind文件如何上传金山文档共享在线编辑?
Redis的两种持久化机制RDB和AOF的原理和优缺点
Programme de jeu de cartes - confrontation homme - machine
一段用蜂鸣器编的音乐(成都)
. Net6: develop modern 3D industrial software based on WPF (2)
这次,彻底搞清楚MySQL索引
C语言入门指南
C language Getting Started Guide
Mortal immortal cultivation pointer-2
随机推荐
[graduation season · advanced technology Er] goodbye, my student days
7-9 制作门牌号3.0(PTA程序设计)
Using spacedesk to realize any device in the LAN as a computer expansion screen
String abc = new String(“abc“),到底创建了几个对象
Caching mechanism of leveldb
使用Spacedesk实现局域网内任意设备作为电脑拓展屏
Principles, advantages and disadvantages of two persistence mechanisms RDB and AOF of redis
Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis
实验五 类和对象
【MySQL数据库的学习】
7-14 错误票据(PTA程序设计)
Have you encountered ABA problems? Let's talk about the following in detail, how to avoid ABA problems
[modern Chinese history] Chapter V test
7-4 散列表查找(PTA程序设计)
Implementation of count (*) in MySQL
7-5 走楼梯升级版(PTA程序设计)
【九阳神功】2016复旦大学应用统计真题+解析
[the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
关于双亲委派机制和类加载的过程
The difference between abstract classes and interfaces