当前位置:网站首页>[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;
边栏推荐
- Nuxtjs quick start (nuxt2)
- ArrayList的自动扩容机制实现原理
- Record a penetration of the cat shed from outside to inside. Library operation extraction flag
- 深度强化文献阅读系列(一):Courier routing and assignment for food delivery service using reinforcement learning
- hashCode()与equals()之间的关系
- 重载和重写的区别
- MySQL中count(*)的实现方式
- 附加简化版示例数据库到SqlServer数据库实例中
- Leetcode.3 无重复字符的最长子串——超过100%的解法
- 实验七 常用类的使用(修正帖)
猜你喜欢
MySQL事务及实现原理全面总结,再也不用担心面试
A comprehensive summary of MySQL transactions and implementation principles, and no longer have to worry about interviews
1. Preliminary exercises of C language (1)
About the parental delegation mechanism and the process of class loading
. Net6: develop modern 3D industrial software based on WPF (2)
7-7 7003 组合锁(PTA程序设计)
【手撕代码】单例模式及生产者/消费者模式
Leetcode. 3. Longest substring without repeated characters - more than 100% solution
Strengthen basic learning records
Meituan dynamic thread pool practice ideas, open source
随机推荐
[hand tearing code] single case mode and producer / consumer mode
Miscellaneous talk on May 14
The difference between cookies and sessions
.Xmind文件如何上传金山文档共享在线编辑?
7-3 构造散列表(PTA程序设计)
Zatan 0516
MySQL事务及实现原理全面总结,再也不用担心面试
仿牛客技术博客项目常见问题及解答(二)
Leetcode.3 无重复字符的最长子串——超过100%的解法
Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis
强化学习基础记录
Strengthen basic learning records
这次,彻底搞清楚MySQL索引
fianl、finally、finalize三者的区别
FAQs and answers to the imitation Niuke technology blog project (I)
强化学习基础记录
7-11 机工士姆斯塔迪奥(PTA程序设计)
JS several ways to judge whether an object is an array
The difference between abstract classes and interfaces
5月14日杂谈