更新时间:2023-11-30 20:04:58
检查此链接
http://www.w3schools.com/sql/sql_foreignkey.asp [ http://www.1keydata.com/sql/sql-foreign-key.html [ ^ ]
他们会帮助您
此链接也将指导您
^ ]
Check this link
http://www.w3schools.com/sql/sql_foreignkey.asp[^]
http://www.1keydata.com/sql/sql-foreign-key.html[^]
They will help you
This link too will guide you
http://blog.sqlauthority.com/2008/09/08/sql-server-%E2%80%93-2008-creating-primary-key-foreign-key-and-default-constraint/[^]
您需要告诉SQL外键引用哪个表:
You need to tell SQL which table the foreign key refers to:
EMP_ID int NOT NULL foreign key REFERENCES empDetails,
顺便说一句,将两个密钥声明为相同大小是个好主意-如果您显式地声明int(11)
为一个密钥,则还应该使用int(11)
作为外键,而不仅仅是int
BTW, the would be a good idea to declare both keys to be the same size - if you explicitly state int(11)
for one, your should also use int(11)
for the foreign key rather than just int
首先INT(11)无效,您不能在数据类型INT上指定列长.
创建表empDetails(
EMP_ID int主键NOT NULL,
密码varchar(10)NOT NULL
);
创建表LEAVE_DETAILS_ADMIN(
EMP_ID int NOT NULL外键引用empDetails(EMP_ID),
LeaveEarnedCredit float(2),
LeaveCasualCredit float(2),
LeaveMaternityCredit float(2)
);
试试这个,Hop会很好用的.....
***的:-)
First of all INT(11) is INVALID, You can''t specify the column length on the data type INT..
CREATE TABLE empDetails (
EMP_ID int primary key NOT NULL,
password varchar(10) NOT NULL
);
CREATE TABLE LEAVE_DETAILS_ADMIN (
EMP_ID int NOT NULL foreign key references empDetails(EMP_ID) ,
leaveEarnedCredit float(2),
leaveCasualCredit float(2),
leaveMaternityCredit float(2)
);
try this, Hop will works fine,....
All the Best:-)