关系:
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值并插入R VALUES sqr?
对于字母B,这是一个约束吗?我是否需要重新制作数据库并让它使用InnoDB? (我不确定这意味着什么我只知道它意味着我可以使用约束......?....
字母C和D是我的前线。 “从R WHERE中删除”; ?
对于最后三个,我该如何进行这些更改?我很确定UPDATE命令。像
这样的东西UPDATE pc SET ram = 2*ram, hd = hd + 60;
提前感谢您的帮助!
答案 0 :(得分:0)
你应该始终以
开头 start transaction;
如果更改符合预期,则以commit;
结束;如果不符合,则以rollback;
结束,这将使状态恢复到启动事务命令之前。
A
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为(从pc中选择*);
祝你好运