[Cialug] SQL Question: Advanced INSERT INTO

Tim Wilson tim_linux at wilson-home.com
Fri Sep 3 16:31:25 CDT 2010


If it is already defined, and it isn't an auto increment type of field, you
can set up a stored procedure, and a trigger.  Set up the trigger on an
insert and have it call the stored procedure.  Then the stored procedure
queries and updates the field.  But, you would be better off defining it as
a SERIAL field if you can.  I do something similar in Postgres for a "last
updated" field, except it is setting the field to the current date and time.

On Fri, Sep 3, 2010 at 2:50 PM, Kenneth Younger <kyounger at gmail.com> wrote:

> Correct. If it's an auto_increment "counter", then just specify NULL as the
> value for that column and it will handle the auto increment.
>
>
> On Fri, Sep 3, 2010 at 2:47 PM, Eric Junker <eric at eric.nu> wrote:
>
>> On 9/3/2010 2:34 PM, Todd Walton wrote:
>> > I'm wondering, if I need to do an INSERT INTO a table, and the table
>> > has a counter for a primary key, how do I handle setting the counter?
>> > I don't know beforehand what it should be, and it could change second
>> > by second.  Would something like this work?:
>>
>> Are you using MySQL? If so, it is probably an auto_increment primary
>> key. You don't need to specify it when inserting as it will
>> automatically increment and set the primary key when you insert.
>>
>> http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
>>
>> Eric
>> _______________________________________________
>> Cialug mailing list
>> Cialug at cialug.org
>> http://cialug.org/mailman/listinfo/cialug
>>
>
>
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>
>


-- 
Tim
Required reading: http://bccplease.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cialug.org/pipermail/cialug/attachments/20100903/df8635df/attachment.htm 


More information about the Cialug mailing list