|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
Re: 2 questions on Auto Increment fields
From: Scott Noyes (snoyes
gmail.com)
Date: Fri Aug 05 2005 - 18:10:40 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> 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
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]