Page 1 of 1

MySQL:insert at mysql cmd line when using auto_increment

Posted: Thu May 23, 2002 4:27 am
by dickey
Given the example table;
CREATE TABLE mytable
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
desc VARCHAR(30) NOT NULL
);

How do I insert records at the command line to utilise the auto_increment feature of MySQL.

i.e. INSERT INTO mytable VALUES(?,"description");

Any assistance will be greatly appreciated.

-Dickey

answering my own post

Posted: Thu May 23, 2002 5:20 am
by dickey
INSERT INTO mytable VALUES(id,"description");

Posted: Thu May 23, 2002 5:47 am
by MattF
You can use this "INSERT INTO mytable (desc) values ("desciption")"

The auto id bit will be automatic.

for readability, I always insert zero

Posted: Sat Jun 01, 2002 10:41 am
by Bill H

Code: Select all

$Query = "INSERT INTO Inst (id, Name, Abbr) VALUES (0, '$Name','$Abbr')";
MySQL accepts zero and changes it to one number greater than.....

Posted: Sat Jun 01, 2002 2:20 pm
by ozmodiar
This is the way I do it

Code: Select all

INSERT INTO mytable VALUES('','description');
Hope this helps