<?php
$sql = "CREATE TABLE bands (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(32) UNIQUE,
born VARCHAR(32),
died VARCHAR(32),
band VARCHAR(32),
lineup VARCHAR(64)
)";
$db->Exec($sql);
$sql = "INSERT INTO bands VALUES (
NULL,
'John Lennon',
'1940 Liverpool',
'1980 New York',
'The Beatles',
'vocals, guitar, harmonica, piano, keyboards')";
$db->Exec($sql);
$sql = "INSERT INTO bands VALUES (
NULL,
'Paul McCartney',
'1942 Liverpool',
'',
'The Beatles',
'vocals, bass, lead guitar, piano, keyboards')";
$db->Exec($sql);
?>
I use the above script.
It works perfect to insert. I use NULL as a 'dummy' for the 'id' in insert.
As you can see I use
id INTEGER AUTO_INCREMENT PRIMARY KEY,
Now in many places including the MySQL Reference Manual
I see they use NOT NULL
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
If I do like I do, not using NOT NULL in my AUTO_INCREMENT PRIMARY.
what is the problem??
As I said, it works perfectly without NOT NULL.
Even when INSERT NULL value!