2015-11-05 61 views
0
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。它告訴我架構已準備就緒,但每次我都做簡單的Sqlfiddle問題

Select * from Sales; 

我得到響應表銷售不存在。任何想法,爲什麼?我只是在這個網站上做這件事,因爲這是我的學校希望我從屏幕截圖上顯示代碼正常工作的地方。

+0

我相信我的錯誤,導致該表不能創建是在創建表的銷售代碼部分。我做了很多改變,但我永遠不會回來,取得好成績。任何人都可以看到我在該代碼段中看不到的問題。 –

+0

SQLFiddle崩潰經常最近..正如你所指出的那樣不顯示簡單'SELECT's結果,不管理連接到數據庫驅動程序等...(*它使用的是一年左右較爲穩定以前,我不認爲你可以責怪你的代碼*) –

+0

以及咬人,這是學校的一個項目,我必須提供從sqlfiddle展示它的工作截圖。我已經向管理員發送了一條消息,告訴我有關不斷崩潰的消息。 –

回答

0

架構

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 (1, 1), 
(2, 5), 
(3, 12), 
(4, 3), 
(5, 4), 
(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 (1, 1, 20151104, 'Please Include plates and napkins'); 

SQL語句

Select * from Sales; 

結果

+-------+----------+---------------+--------------------------+----------------------------------------------+ 
|ORDERID|CustomerID|DoughnutOrderID|Date      |SpecialHandlingInstructions     | 
-------------------------------------------------------------------------------------------------------------- 
|1  |1   |1    |November, 04 2015 00:00:00|Please Include plates and napkins