这是创建外键表示表的方法
CREATE TABLE `ffxi_characterJob` (
`serverID` int(11) NOT NULL,
`userid` int(10)unsigned NOT NULL,
`characterName` varchar(255) NOT NULL,
`jobAbbr` char(4) NOT NULL,
`jobLevel` int(11) default '0',
PRIMARY KEY (`serverID`,`userid`,`characterName`,`jobAbbr`),
INDEX (`jobAbbr`),
CONSTRAINT FOREIGN KEY (`serverID`,`userid`,`characterName`) REFERENCES `ffxi_characters` (`serverID`,`userid`,`characterName`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (`jobAbbr`) REFERENCES `ffxi_jobType` (`jobAbbr`) ON DELETE CASCADE ON UPDATE CASCADE
) TYPE=InnoDB;
因为如果您像这样创建,那么当您更改第一个(主)表中的值时它会自动删除或更新,插入您需要放置与第一个表的列值匹配的值
emp_id name value
1 aaa 24
2 bbb 23
3 ccc 25
4 ddd 27
pur_id emp_id amount
000 1 500
001 2 100
002 1 50
在第二个表中,emp_id 是第一个表 emp_id 的外键引用,因此您需要第一个表中的匹配值
$query = "INSERT INTO paycheck(payCheckId,jobId,payRate,jobLocation,hoursWorked,startPeriod,endPeriod, empid)
VALUES('','$pay_rate','$job_location','$hours','$start','$end', 'value that you want t0 match from first table')";