2 questions on Auto Increment fields

2005-08-05 Thread C.F. Scheidecker Antunes

Hello all,

I have two question on Auto Increment fields:

1) For what I see on the MySQL manual you can have an Auto Increment not 
null Field as the primary key. Say that you have a table with only
two columns the first being an Auto_Increment. How do I write an INSERT 
or REPLACE SQL statement to insert data on this table? Can
I write it so that it will only insert a value for the second column or 
do I have to specify NULL on the column on my statement so that MySQL

would fill it up for me.

2) After the INSERT or REPLACE statement runs, can I call something 
(hopefully on the same statement) that would return the value filled on 
the Auto Increment field?


Thanks in advance,

C.F.

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



Re: 2 questions on Auto Increment fields

2005-08-05 Thread Scott Noyes
 1) For what I see on the MySQL manual you can have an Auto Increment not
 null Field as the primary key. Say that you have a table with only
 two columns the first being an Auto_Increment. How do I write an INSERT
 or REPLACE SQL statement to insert data on this table? Can
 I write it so that it will only insert a value for the second column or
 do I have to specify NULL on the column on my statement so that MySQL
 would fill it up for me.

The following all work exactly the same, assuming the setup you have described.
INSERT INTO theTable (theSecondField) VALUES (theSecondValue);
INSERT INTO theTable (theAutoField, theSecondField) VALUES (NULL,
theSecondValue);
INSERT INTO theTable VALUES (NULL, theSecondValue);
 
 2) After the INSERT or REPLACE statement runs, can I call something
 (hopefully on the same statement) that would return the value filled on
 the Auto Increment field?

SELECT LAST_INSERT_ID();

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