At 19:12 +1000 6/1/06, Mark Sargent wrote:
Hi All,

if a table has an auto_incremented primary key why does the below code require the people_id to be manually inserted? I got this from Beginning PHP, Apache, MySQL Web Development book from Wrox. Curious, as it seems to defeat the purpose of auto_increment, no? Cheers.

$people = "INSERT INTO people (people_id, people_full_name, people_isactor, people_isdirector) VALUES (1, 'Jim Carey', 1, 0), (2, 'Tom Shadyac', 0, 1), (3, 'Lawrence Kasdan', 0, 1), (4, 'Kevin Kline', 1, 0), (5, 'Ron Livingston', 1, 0), (6, 'Mike Judge', 0, 1)";
$results = mysql_query($people) or die(mysql_error());

If people_id is the AUTO_INCREMENT primary key, and the table doesn't have
any records with 1 though 6 in the table already, the code should work.
You can insert values into the column if they aren't already there.

But you could also insert NULL (or omit people_id from the statement
entirely), and then MySQL will generate sequence numbers automatically.

--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to