错误 1005 (HY000):无法创建 table 'project2.fulltime'(错误编号:150)
ERROR 1005 (HY000): Can't create table 'project2.fulltime' (errno: 150)
我知道你们都已经回答过这个问题很多次了。如果你有时间请帮忙。它无法创建全职 table 或兼职 table。我收到错误 HY000。厌倦了修复它阅读表格仍然出现错误。谢谢你的时间。
DROP DATABASE project2;
CREATE DATABASE project2;
Use project2;
drop table if exists Customer;
drop table if exists Employee;
drop table if exists Orders;
drop table if exists BookOrder;
drop table if exists FullTime;
drop table if exists PartTime;
CREATE TABLE Customer (
CustomerID int PRIMARY KEY ,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL ,
Address varchar (60) NULL ,
City varchar (25) NULL ,
State varchar (15) NULL ,
Phone varchar (16) NULL ,
Email varchar(50) NULL
);
Insert Into Customer Values(1,'Jhon','Peterson','3265 4th Street','Los Angeles','CA','5625687854','Jhon.Peterson@yahoo.com');
Insert Into Customer Values(2,'Peter','Paker','9587 Church Ave.','Compton','CA','3235687452','Peter.Paker@marvel.com');
Insert Into Customer Values(3,'Yin','May','2354 Bombardier Ave.','New Rochelle','NY','6088565216','Yin.May@hotmail.com');
Insert Into Customer Values(4,'Erick','Ruiz','1234 Franklin Blvd.','Columbus','OH','9065682561','Erick.Ruiz@gmai.com');
Insert Into Customer Values(5,'Alex','Bastidas','5698 Luders Street','Paris','UK','8985354587','Alex.Bastidas@gmail.com');
CREATE TABLE Employee(
EmployeeID int PRIMARY KEY,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL ,
Address varchar (60) NULL ,
City varchar (25) NULL ,
State varchar (15) NULL ,
Phone varchar (16) NULL,
SSN varchar (16) NOT NULL
);
Insert Into Employee Values(32,'Juan','Ortiz','5748 Pine Street','Los Angeles','CA','3232587458','608758955');
Insert Into Employee Values(45,'Mark','Marks','5148 Hatteras','Long Beach','CA','2135487632','405734655');
Insert Into Employee Values(50,'Van','Diesel','4784 Sixth Street','Van Nuys','NC','6058569265','702457822');
Insert Into Employee Values(16,'June','Franks','98456 Home Ave.','Ontario','NJ','5624875632','608159555');
Insert Into Employee Values(22,'Adrianna','Ornals','498756 Bronxs Street','Brooklyn','NY','1234567888','123456789');
CREATE TABLE Orders (
OrderID int PRIMARY KEY ,
CustomerID int (50) NULL ,
EmployeeID int (50) NOT NULL
);
Insert Into Orders Values(10,5,32);
Insert Into Orders Values(14,3,45);
Insert Into Orders Values(11,2,16);
Insert Into Orders Values(13,1,50);
Insert Into Orders Values(12,4,22);
CREATE TABLE BookOrder(
BookID int (50) NOT NULL,
OrderID int (50) NOT NULL ,
OrderQuantity int (50) NOT NULL,
CONSTRAINT BookOrderPK PRIMARY KEY(BookID,OrderID)
);
Insert Into BookOrder Values(1,14,7);
Insert Into BookOrder Values(20,10,10);
Insert Into BookOrder Values(34,11,25);
Insert Into BookOrder Values(11,12,31);
Insert Into BookOrder Values(21,13,25);
CREATE TABLE Book(
BookID int PRIMARY KEY,
StockQuantity int (50) NOT NULL ,
BookTitle varchar (50) NOT NULL ,
BookAuthor varchar (50) NOT NULL,
BookPrice decimal(4,2) NOT NULL
);
Insert Into Book Values(22,10,'Literature', 'Mark Patternson', 60.99);
Insert Into Book Values(64,25,'Calculus', 'Gilbert Strang', 187.99);
Insert Into Book Values(87,30,'Java', 'Daniel Liang', 150.99);
Insert Into Book Values(90,40,'Philosophy', 'Marcus Aurelius', 90.99);
Insert Into Book Values(77,5,'Social Engineering', 'Christopher Hadnagy', 100.99);
CREATE TABLE FullTime(
EmployeeID int PRIMARY KEY,
Salary varchar(50) NOT NULL,
SSN varchar (16) NOT NULL,
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID),
FOREIGN KEY (SSN) REFERENCES Employee(SSN)
);
Insert Into FullTime Values(22,'62,990','123456789');
Insert Into FullTime Values(50,'51,730','702457822');
Insert Into FullTime Values(45,'46,990','405734655');
CREATE TABLE PartTime(
EmployeeID int PRIMARY KEY,
HourlyRate decimal(4,2) NOT NULL,
TotalHours int (40) NOT NULL,
SSN varchar (16) NOT NULL,
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID),
FOREIGN KEY (SSN) REFERENCES Employee(SSN)
);
Insert Into PartTime Values(32,32.00,35,'608758955');
Insert Into PartTime Values(16,40.00,38,'608159555');
你需要让employeetable中的SSN成为一个唯一的键,不管怎样都是现实生活中的,这样才能作为外键引用:
CREATE TABLE Employee(
EmployeeID int PRIMARY KEY,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL ,
Address varchar (60) NULL ,
City varchar (25) NULL ,
State varchar (15) NULL ,
Phone varchar (16) NULL,
SSN varchar (16) NOT NULL,
unique(SSN)
);
我知道你们都已经回答过这个问题很多次了。如果你有时间请帮忙。它无法创建全职 table 或兼职 table。我收到错误 HY000。厌倦了修复它阅读表格仍然出现错误。谢谢你的时间。
DROP DATABASE project2;
CREATE DATABASE project2;
Use project2;
drop table if exists Customer;
drop table if exists Employee;
drop table if exists Orders;
drop table if exists BookOrder;
drop table if exists FullTime;
drop table if exists PartTime;
CREATE TABLE Customer (
CustomerID int PRIMARY KEY ,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL ,
Address varchar (60) NULL ,
City varchar (25) NULL ,
State varchar (15) NULL ,
Phone varchar (16) NULL ,
Email varchar(50) NULL
);
Insert Into Customer Values(1,'Jhon','Peterson','3265 4th Street','Los Angeles','CA','5625687854','Jhon.Peterson@yahoo.com');
Insert Into Customer Values(2,'Peter','Paker','9587 Church Ave.','Compton','CA','3235687452','Peter.Paker@marvel.com');
Insert Into Customer Values(3,'Yin','May','2354 Bombardier Ave.','New Rochelle','NY','6088565216','Yin.May@hotmail.com');
Insert Into Customer Values(4,'Erick','Ruiz','1234 Franklin Blvd.','Columbus','OH','9065682561','Erick.Ruiz@gmai.com');
Insert Into Customer Values(5,'Alex','Bastidas','5698 Luders Street','Paris','UK','8985354587','Alex.Bastidas@gmail.com');
CREATE TABLE Employee(
EmployeeID int PRIMARY KEY,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL ,
Address varchar (60) NULL ,
City varchar (25) NULL ,
State varchar (15) NULL ,
Phone varchar (16) NULL,
SSN varchar (16) NOT NULL
);
Insert Into Employee Values(32,'Juan','Ortiz','5748 Pine Street','Los Angeles','CA','3232587458','608758955');
Insert Into Employee Values(45,'Mark','Marks','5148 Hatteras','Long Beach','CA','2135487632','405734655');
Insert Into Employee Values(50,'Van','Diesel','4784 Sixth Street','Van Nuys','NC','6058569265','702457822');
Insert Into Employee Values(16,'June','Franks','98456 Home Ave.','Ontario','NJ','5624875632','608159555');
Insert Into Employee Values(22,'Adrianna','Ornals','498756 Bronxs Street','Brooklyn','NY','1234567888','123456789');
CREATE TABLE Orders (
OrderID int PRIMARY KEY ,
CustomerID int (50) NULL ,
EmployeeID int (50) NOT NULL
);
Insert Into Orders Values(10,5,32);
Insert Into Orders Values(14,3,45);
Insert Into Orders Values(11,2,16);
Insert Into Orders Values(13,1,50);
Insert Into Orders Values(12,4,22);
CREATE TABLE BookOrder(
BookID int (50) NOT NULL,
OrderID int (50) NOT NULL ,
OrderQuantity int (50) NOT NULL,
CONSTRAINT BookOrderPK PRIMARY KEY(BookID,OrderID)
);
Insert Into BookOrder Values(1,14,7);
Insert Into BookOrder Values(20,10,10);
Insert Into BookOrder Values(34,11,25);
Insert Into BookOrder Values(11,12,31);
Insert Into BookOrder Values(21,13,25);
CREATE TABLE Book(
BookID int PRIMARY KEY,
StockQuantity int (50) NOT NULL ,
BookTitle varchar (50) NOT NULL ,
BookAuthor varchar (50) NOT NULL,
BookPrice decimal(4,2) NOT NULL
);
Insert Into Book Values(22,10,'Literature', 'Mark Patternson', 60.99);
Insert Into Book Values(64,25,'Calculus', 'Gilbert Strang', 187.99);
Insert Into Book Values(87,30,'Java', 'Daniel Liang', 150.99);
Insert Into Book Values(90,40,'Philosophy', 'Marcus Aurelius', 90.99);
Insert Into Book Values(77,5,'Social Engineering', 'Christopher Hadnagy', 100.99);
CREATE TABLE FullTime(
EmployeeID int PRIMARY KEY,
Salary varchar(50) NOT NULL,
SSN varchar (16) NOT NULL,
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID),
FOREIGN KEY (SSN) REFERENCES Employee(SSN)
);
Insert Into FullTime Values(22,'62,990','123456789');
Insert Into FullTime Values(50,'51,730','702457822');
Insert Into FullTime Values(45,'46,990','405734655');
CREATE TABLE PartTime(
EmployeeID int PRIMARY KEY,
HourlyRate decimal(4,2) NOT NULL,
TotalHours int (40) NOT NULL,
SSN varchar (16) NOT NULL,
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID),
FOREIGN KEY (SSN) REFERENCES Employee(SSN)
);
Insert Into PartTime Values(32,32.00,35,'608758955');
Insert Into PartTime Values(16,40.00,38,'608159555');
你需要让employeetable中的SSN成为一个唯一的键,不管怎样都是现实生活中的,这样才能作为外键引用:
CREATE TABLE Employee(
EmployeeID int PRIMARY KEY,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL ,
Address varchar (60) NULL ,
City varchar (25) NULL ,
State varchar (15) NULL ,
Phone varchar (16) NULL,
SSN varchar (16) NOT NULL,
unique(SSN)
);