当前位置:网站首页>[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;
边栏推荐
- Zatan 0516
- [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
- 【头歌educoder数据表中数据的插入、修改和删除】
- Detailed explanation of redis' distributed lock principle
- Leetcode. 3. Longest substring without repeated characters - more than 100% solution
- [modern Chinese history] Chapter 9 test
- It's never too late to start. The tramp transformation programmer has an annual salary of more than 700000 yuan
- 2022 Teddy cup data mining challenge question C idea and post game summary
- 稻 城 亚 丁
- [the Nine Yang Manual] 2021 Fudan University Applied Statistics real problem + analysis
猜你喜欢
Custom RPC project - frequently asked questions and explanations (Registration Center)
The latest tank battle 2022 full development notes-1
4. Branch statements and loop statements
FAQs and answers to the imitation Niuke technology blog project (II)
Write a program to simulate the traffic lights in real life.
[面试时]——我如何讲清楚TCP实现可靠传输的机制
透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
仿牛客技术博客项目常见问题及解答(三)
强化学习基础记录
canvas基础2 - arc - 画弧线
随机推荐
Have you encountered ABA problems? Let's talk about the following in detail, how to avoid ABA problems
编写程序,模拟现实生活中的交通信号灯。
力扣152题乘数最大子数组
稻 城 亚 丁
Brief introduction to XHR - basic use of XHR
7-9 制作门牌号3.0(PTA程序设计)
Miscellaneous talk on May 14
. Net6: develop modern 3D industrial software based on WPF (2)
Nuxtjs quick start (nuxt2)
Why use redis
7-4 散列表查找(PTA程序设计)
[modern Chinese history] Chapter V test
自定义RPC项目——常见问题及详解(注册中心)
MySQL锁总结(全面简洁 + 图文详解)
[graduation season · advanced technology Er] goodbye, my student days
Matlab opens M file garbled solution
MATLAB打开.m文件乱码解决办法
7-1 输出2到n之间的全部素数(PTA程序设计)
Beautified table style
Strengthen basic learning records