0

关系:

Product( maker, model, type )
PC( model, speed, ram, hd, price)
Laptop( model, speed, ram, hd, screen, price)
Printer( model, color, type, price)

A. Using two INSERT statements, store in the database the fact that PC model 1100 is made by manufacturer C, has a speed of 3.2, and RAM 1024, hard disk 180, and sells $2499
B. Insert the facts that for every pc there is a laptop with the same manufacturer, speed, ram, and hard disk, a 17 inch screen, a model number 1100 greater, and a price 500 more
C. Delete all pc's with less than 100 gigabytes of hd space
D. Delete all laptops made by a manufacturer that doesn't make printers
E. Manufacturer A buys Manufacturer B. Change all products made by b so now they are made by a.
F. For each pc, double the amount of RAM and add 60gb to the amount of hd. 
G. For each laptop made by manufacturer b, add one inch to the screen size and subtract 100 from the price

首先对于这些示例中的每一个,我将修改我的数据库,有没有办法快速复制我的数据库,以防我搞砸了更改?

我该如何对问题 A 使用两个插入语句?我知道“插入 R(A,B,C)值(a,b,c);” 我应该插入 R 值 xyz 和插入 R 值 sqr 吗?

对于字母 B,这是一个约束吗?我是否需要重新制作我的数据库并让它使用 InnoDB?(我不确定这意味着什么,我只知道这意味着我可以使用约束......?......

字母 C 和 D 对我来说很困难。“从 R 中删除;” ?

对于最后三个,我该如何进行这些更改?我很确定 UPDATE 命令。所以像

UPDATE pc SET ram = 2*ram, hd = hd + 60;

提前感谢您的帮助!

4

1 回答 1

0

你应该总是从

start transaction;

并以commit;更改是否符合预期或rollback;未按预期结束,这会将状态恢复到开始事务命令之前的状态。

一个

insert into Product( maker, model, type ) values ('C','1100'...);
insert into PC( model, speed, ram, hd, price) values ('1100',.....);

insert into Laptop( model, speed, ram, hd, screen, price) select model,speed,ram,hd,'17',price-100 from pc;

像这样的东西

对于其他人,你在正确的轨道上。

确保使用事务不要弄乱您的数据,您可以按照建议使用 mysql 转储或简单地创建备份表

创建表 pcBAK 为 (Select * from pc);

祝你好运

于 2012-04-12T19:34:56.257 回答