For the sake of simplicity lets say I have a table with 3 columns; id
, parent_id
and name
. In this table id
is my auto-incrementing primary key. I want to group multiple names together in this table, to do this all names in a group will share the same parent_id
. If I am inserting the the first name in the group I want the id
=parent_id
, if i am inserting another name I want to specify a specific parent_id to place that name into a specific group. It would be nice if I could define a default for that column to be the same as the id, if I specify a value for parent_id
in the insert query then I would like it to use that value. I know you can set a default to be a specific static value, but can you specify the default to be the same as that row's auto-incrementing primary key? Perhaps this is a job for a trigger or stored procedure?
(I know I could obtain the primary key generated by the last insert and then update the table, but that's 2 quires I'd rather not burn.)
Thanks!