我使用了以下语法。请在这个问题上帮助我创建外键。
mysql> create table userdetails(UserId int(3) not null, ClientId int(3) not null, UserName varchar(30), Password varchar(30) character set binary, RoleId int(3) not null, primary key(UserId, ClientId), foreign key(RoleId) references UserRoles(RoleId) on delete cascade on update cascade)ENGINE=InnoDB DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.44 sec)
mysql> create table useraddress (UserId int(3) NOT NULL, Address1 varchar(100),Address2 varchar(100), City varchar(50), Pincode varchar(10), PhoneNumber varchar(20), MobileNumber varchar(20), foreign key(UserId) references userdetails(UserId)on delete cascade on update cascade) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.09 sec)
mysql> create table clientaddressdetails (Address1 varchar(100), Address2 varchar(100), City varchar(50), Pincode varchar(10), PhoneNumber varchar(20), MobileNumber varchar(20), ClientId int(3), foreign key(ClientId) references userdetails(ClientId)on delete cascade on update cascade) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ERROR 1005 (HY000): Can't create table '.\mydb\clientaddressdetails.frm' (errno: 150)