首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sqlfiddle问题

Sqlfiddle问题
EN

Stack Overflow用户
提问于 2015-11-05 08:05:07
回答 1查看 762关注 0票数 0
代码语言:javascript
复制
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。它告诉我模式已经准备好了,但是每次我执行简单的

代码语言:javascript
复制
Select * from Sales;

我得到的响应表sales不存在。有什么想法可以解释原因吗?我之所以在这个网站上这样做,是因为我的学校希望我在这个网站上截取屏幕截图,以展示代码的工作。

EN

回答 1

Stack Overflow用户

发布于 2016-12-20 15:11:48

模式

代码语言:javascript
复制
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语句

代码语言:javascript
复制
Select * from Sales;

结果

代码语言:javascript
复制
+-------+----------+---------------+--------------------------+----------------------------------------------+
|ORDERID|CustomerID|DoughnutOrderID|Date                      |SpecialHandlingInstructions                   |
--------------------------------------------------------------------------------------------------------------
|1      |1         |1              |November, 04 2015 00:00:00|Please Include plates and napkins
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33534442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档