当前位置:网站首页>[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
orderNochar(12) The order number , Main code
orderDatedate subscription date
customerNochar(12) Customer number , Outer code , And customer.customerNo Corresponding
employeeNochar(12) Employee number , Outer code , And employee.employeeNo Corresponding

orderDetail surface

Field name data type remarks
orderNochar(12) The order number , Main attribute , Outer code , And order.orderNo Corresponding
productNochar(12) Product number , Main attribute , Outer code , And product.productNo Corresponding
quantityOrderedint Order quantity
orderDatedate subscription date

notes : surface orderDetail The main code of is (orderNo,productNo) form

The task of programming is to orderDetail Table to be modified :

  1. 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.
  2. 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
unitPricenumeric(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
serialNoint auto number , Main code
namechar(32) full name
companychar(32) Work unit
positionchar(10) Position
workPhonechar(16) Office phone
mobilechar(11) mobile phone
QQintQQ Number
weixinchar(12) WeChat ID

The original statement to create the table is as follows :

  1. create table addressBook(
  2. serialNo int auto_increment primary key,
  3. name char(32),
  4. company char(32),
  5. position char(10),
  6. workPhone char(16),
  7. mobile char(11),
  8. QQ int,
  9. weixin char(12)
  10. );

Your programming task is to check the table addressBook Make the following modifications :

  1. take QQ The data type of No. is changed to char(12);
  2. 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;

原网站

版权声明
本文为[Fu Ying ('▿')]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060917206433.html