SQL新手,需要检查小提琴上的功课 - 我的代码是否正确?

时间:2017-05-14 17:18:21

标签: sql sqlfiddle

CREATE TABLE Customer_Master(   customer_ID INTEGER(30)NOT NULL AUTO_INCREMENT,   first_name VARCHAR(100)NOT NULL,   last_name VARCHAR(100)NOT NULL,   street_address VARCHAR(100)NOT NULL,   apt INTEGER(9),   city VARCHAR(30)NOT NULL,   state VARCHAR(3)NOT NULL,   zip VARCHAR(10)NOT NULL,   home_phone INTEGER NOT NULL,   mobile_phone INTEGER(10)NOT NULL,   other_phone INTEGER(10)NOT NULL,   PRIMARY KEY(customer_ID) );

CREATE TABLE Order_Master(   Donut_order_ID INTEGER(10)NOT NULL,   Order_date DATETIME NOT NULL,   Special_notes VARCHAR(255)NOT NULL,   Customer_ID INTEGER(30)NOT NULL,   PRIMARY KEY(Donut_order_ID),   FOREIGN KEY(Customer_ID)REFERENCES Customer_Master(Customer_ID) );

创建表Donut_Master(   Donut_ID VARCHAR(10)NOT NULL,   名称VARCHAR(30)NOT NULL,   Unit_price NUMERIC(10,2)NOT NULL,   主要钥匙(Donut_ID) );

CREATE TABLE Order_Details(   Donut_Order_ID INTEGER(10)NOT NULL,   Donut_ID VARCHAR(10)NOT NULL,   数量INTEGER(100)NOT NULL,   FOREIGN KEY(Donut_Order_ID)REFERENCES Order_Master(Donut_Order_ID),
  FOREIGN KEY(Donut_ID)参考文献Donut_Master(Donut_ID) );

创建视图Customer_Information AS  SELECT CONCAT(first_name,'',last_name)AS Customer_Name, customer_ID,street_address,apt,city,state,zip,home_phone,mobile_phone,other_phone  来自Customer_Master;

创建指数甜甜圈 在Donut_Master(Donut_ID);

INSERT INTO Customer_Master VALUES  ( '1', '布鲁斯', '韦恩', '123_Gotham', '12', 'Gotham_City',    'NY', '12345', '123456789', '000000000', '000000000');

INSERT INTO Order_Master   VALUES('1','2017-05-11','Please_include_plates_and_napkins','1');

INSERT INTO Donut_Master   VALUES ( '1', '普通', '1.50'), ( '2', '上釉', '1.75'), ( '3', '肉桂', '1.75'), ( '4', '巧克力', '1.75'), ( '5', '撒上', '1.75'), ( '6', '无麸质', '2.00'); INSERT INTO Order_Details 价值观('1','1','1');

1 个答案:

答案 0 :(得分:0)

嗯,你得到的错误应该足够清楚,以解决任何错误。 有一些拼写错误,例如表Donut_Master的CREATE语句中的额外逗号,Order_Details的Customer_ID为varchar,而Customer_Master为int。我认为您的INSERT语句也不完整,请参阅此处:https://www.w3schools.com/sql/sql_insert.asp 这些是你可以经历的一些很棒的课程!祝你好运!