MySQL:insert at mysql cmd line when using auto_increment

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dickey
Forum Commoner
Posts: 50
Joined: Thu May 16, 2002 8:04 pm
Location: Sydney, Australia

MySQL:insert at mysql cmd line when using auto_increment

Post 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
dickey
Forum Commoner
Posts: 50
Joined: Thu May 16, 2002 8:04 pm
Location: Sydney, Australia

answering my own post

Post by dickey »

INSERT INTO mytable VALUES(id,"description");
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

You can use this "INSERT INTO mytable (desc) values ("desciption")"

The auto id bit will be automatic.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

for readability, I always insert zero

Post 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.....
ozmodiar
Forum Commoner
Posts: 35
Joined: Sat Jun 01, 2002 6:29 am
Location: Dublin, Ireland

Post by ozmodiar »

This is the way I do it

Code: Select all

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