SQL错误
我不确定我在这里做错了什么
这是我用来创建表格的DDL
RewriteCond %{HTTP_HOST} ^(sub\.domain1\.com|sub\.domain2\.com|sub\.domain3\.com)$ [NC]
RewriteRule ^register/(.*)$ http://domain.com/register/$1 [R=301,L]
这是我用来尝试填写员工表的命令
Create Table HomeState (StateAbbreviation char(2) Primary Key,
StateName varchar(25));
Create Table Country (CountryAbbreviation char(2) Primary Key,
CountryName varchar(35));
Create Table Employee (EmployeeID Integer Primary Key NOT NULL,
FirstName varchar(20),
LastName varchar(30),
MI char(1),
HomeAddress varchar(30),
Zip char(5),
DateOfBirth date,
HireDate date,
TerminationDate date,
AnnualSalary number(20,2),
LicenseDate date,
StateAbbreviation char(2),
CountryAbbreviation char(2),
Foreign Key (StateAbbreviation) references HomeState,
Foreign Key (CountryAbbreviation) references Country);
Create Table Truck (VinNumber Integer Primary Key,
Make varchar(25),
Model varchar(30),
Year Integer,
PurchasePrice number(20,2),
LicenseNumber varchar(15));
Create Table EmployeeTruck (EmployeeID Integer,
VinNumber Integer,
Primary Key(EmployeeID,VinNumber),
Foreign Key (EmployeeID) references Employee,
Foreign Key (VinNumber) references Truck);
Create Table Accident (AccidentID Integer Primary Key,
DateOfAccident date,
AccidentDescription varchar(200),
AccidentLocation varchar(100),
EmployeeID Integer,
Foreign Key (EmployeeID) references Employee);
但是它总是给我一个错误,我把它作为这个问题的标题......
答案 0 :(得分:0)
在表格"员工"中,您说Foreign Key (StateAbbreviation) references HomeState
和Foreign Key (CountryAbbreviation) references Country)
。在插入Employee之前,插入Employee.HomeState和Employee.CountryAbbreviation的值必须存在于HomeState和Country表中。
在插入Employee之前,将行插入HomeState和Country。
你也有其他问题。这是一个例子。
Create Table HomeState (StateAbbreviation char(2) Primary Key,
StateName varchar(25));
insert into HomeState values ('AL', 'Alabama');
insert into HomeState values ('AM', 'Alabama');
insert into HomeState values ('AN', 'Alabama');
所有这些插入语句都成功。他们不应该。在这种情况下,StateName也是候选键。
Create Table HomeState (
StateAbbreviation char(2) Primary Key,
StateName varchar(25) not null unique
);
让我们更进一步。
Create Table HomeState (
StateAbbreviation char(2) Primary Key,
StateName varchar(25) not null unique
);
Create Table Country (
CountryAbbreviation char(2) Primary Key,
CountryName varchar(35) not null unique
);
insert into HomeState values ('CA', 'California');
insert into Country values ('AF', 'Afghanistan');
insert into Employee (EmployeeID, StateAbbreviation, CountryAbbreviation)
values (-42, 'CA', 'AF');
州"加利福尼亚州,美国"说得通。国家"加利福尼亚,阿富汗"没有按'吨。
没有名字的员工没有意义。声明FirstName,LastName和HireDate not null
。
打赌:无论你的数据库允许 出现什么废话。这只是时间问题。