【发布时间】:2015-11-05 00:05:07
【问题描述】:
Create table customer
(CustomerID int(255) not null auto_increment,
FirstName varchar(255) not null,
LastName varchar(255) not null,
StreetAddress char(255) not null,
Apartment varchar(255) not null,
City varchar(255) not null,
State varchar(2) not null,
ZipCode int(9) not null,
HomePhone int(10) not null,
MobilePhone int(10) not null,
OtherPhone int(10) not null,
Primary Key (CustomerID));
insert into Customer
(FirstName, LastName, StreetAddress, Apartment, City, State,
ZipCode, HomePhone, MobilePhone, OtherPhone)
Values ("Ken", "Weger", "StreetAddress", "Apartment", "City",
"ST", 123456789, 1111111111, 222222222, 333333333);
Create Table Doughnut
(DoughnutID int(255) not null auto_increment,
Name varchar(255) not null,
Description varchar(255) not null,
UnitPrice decimal(3,2) not null,
Primary Key (DoughnutID));
insert into Doughnut (Name, Description, UnitPrice)
Values ("Plain", "Plain Donut", "1.50"),
("Glazed", "Glazed Donut", "1.75"),
("Cinnamon", "Cinnamon Donut", "1.75"),
("Chocolate", "Chocolate Donut", "1.75"),
("Sprinkle", "Sprinkle Donut", "1.75"),
("Gluten-Free", "Gluten-Free Donut", "2.00");
Create Table DoughnutOrder
(DoughnutOrderID int(255) not null auto_increment,
DoughnutID int(255),
Quantity int(255),
Primary Key (DoughnutOrderID),
Index Doughnut(doughnutid),
Foreign Key (DoughnutID) References Doughnut(DoughnutID));
Insert into Doughnutorder (DoughnutId, Quantity)
values ((select DoughnutId from Doughnut where doughnutid = 1), 1),
((select DoughnutId from Doughnut where doughnutid = 2), 5),
((select DoughnutId from Doughnut where doughnutid = 3), 12),
((select DoughnutId from Doughnut where doughnutid = 4), 3),
((select DoughnutId from Doughnut where doughnutid = 5), 4),
((select DoughnutId from Doughnut where doughnutid =6), 5);
Create Table Sales
(ORDERID int(255) not null Auto-increment,
CustomerID int(255) not null,
DoughnutOrderID int(255) not null,
`Date` date not null,
SpecialHandlingInstructions varchar(255),
Primary Key (ORDERID),
Index Customer (customerID),
Foreign Key (customerid) References customer(customerid),
Index doughnutorder (doughnutorderid),
Foreign Key (doughnutorderid) references doughnutorder(doughnutorderid);
Insert into Sales (Customerid, DoughnutorderID, `date`, SpecialHandlingInstructions)
Values ((select customerid from customer), (select DoughnutOrderID from DoughnutOrder), 20151104, Please Include plates and napkins);
我正在 sqlfiddle 上使用它。它告诉我架构已准备好,但每次我做一个简单的操作时
Select * from Sales;
我得到响应表销售不存在。关于为什么的任何想法?我只在这个网站上这样做,因为我的学校希望我从那里截取屏幕截图以显示代码有效。
【问题讨论】:
-
我相信导致表无法创建的错误出现在创建表销售部分的代码中。我做了很多改变,但我永远无法以好的结果回来。谁能看到我在那段代码中没有看到的问题。
-
SQLFiddle 最近经常崩溃。正如您所指出的,没有显示简单
SELECTs 的结果,无法连接到数据库驱动程序等...(大约一年前它曾经更稳定,我认为你不能责怪你的代码) -
好吧,这是一个学校项目,我必须提供来自 sqlfiddle 的屏幕截图,显示它工作正常。我已经向视线的管理员发送了一条消息,说明我一直在不断崩溃。