[英]How do I INSERT the contents of a table into another, but excluding their Primary Key (id's)?
I am trying to merge contents of two tables into one (sortedArrivals) using the following code: I do not want the Primary Key id's (here called flightShed.id) to be inserted. 我试图使用以下代码将两个表的内容合并为一个表(sortedArrivals):我不希望插入主键ID(在此称为flightShed.id)。
$sql = "INSERT INTO sortedArrivals
SELECT flightSched.id,
flightSched.timePeriod,
flightSched.depOrArriv,
flightSched.flightNo,
flightSched.airline,
flightSched.dest,
flightSched.origin,
flightSched.depature,
flightSched.don,
flightSched.arrivalTime,
flightSched.status
FROM flightSched ";
if (!$mysqli->query($sql))
{
echo $counter . "<br>" ;
die('Error: ' . $mysqli->error);
}
However I would like a incrementing Primary Key. 但是我想要一个递增的主键。 When I try inserting the contents of the next table I get: the following error message:
当我尝试插入下一张表的内容时,出现以下错误消息:
Error: Duplicate entry '9' for key 'PRIMARY' 错误:键“ PRIMARY”的条目“ 9”重复
how do i achieve this? 我该如何实现? Any help is appreciated.
任何帮助表示赞赏。
Name the columns you want to insert into 命名要插入的列
INSERT INTO sortedArrivals (timePeriod, depOrArriv, flightNo, airline,
dest, origin, depature, don, arrivalTime, status)
SELECT timePeriod,
depOrArriv,
flightNo,
airline,
dest,
origin,
depature,
don,
arrivalTime,
status
FROM flightSched
I do not want the Primary Key id's (here called flightShed.id) to be inserted.
我不希望插入主键ID(在这里称为flightShed.id)。
Well then don't select them … 好吧,不要选择它们……
However I would like a incrementing Primary Key.
但是我想要一个递增的主键。
… but select just NULL
instead in their place; …但是只选择
NULL
代替它们; a NULL value for an autoindex column will automatically increase the ai counter. 自动索引列的NULL值将自动增加ai计数器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.