If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Insert identity

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-05, 11:10
alx_81 alx_81 is offline
Registered User
 
Join Date: Aug 2003
Posts: 23
Insert identity

Hi to all!

I must do an insert into statement on a identity indexed table:
MSG_ID --> the identity (autoincrement)
MSG_DESCRI
MSG_PARENT --> the field i must fill

I must fill MSG_PARENT with a MSG_ID value, after the insert..
ex:
insert into MESSAGES (MSG_DESCRI,MSG_PARENT)
values ('hello world',identity value after insert)..
what's the best way to do this??

I must do this cause the first node of my tree must have MSG_PARENT = MSD_ID.. the root node..
in sql server i use a stored proc, i exec the insert and i use the @@identity sysvar... but my mysql version don't supports stored procedures..
can anyone help me??

thx!!!
__________________
Alx_81 =)
Reply With Quote
  #2 (permalink)  
Old 03-01-05, 21:32
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
the root node should have parent id set to null

in mysql, you can use last_insert_id() function to retrieve the value
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-02-05, 03:06
alx_81 alx_81 is offline
Registered User
 
Join Date: Aug 2003
Posts: 23
ok.. but

null is not the best for my root node..
but i can use the function that you tell me in last message..
so, under the same transaction that funcion don't return any value..
right? i must wait the commit of my transaction?
But i must do this in one transaction...
__________________
Alx_81 =)
Reply With Quote
  #4 (permalink)  
Old 03-02-05, 05:38
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
read what the manual says about the function, it explains how to use it

and yes, null is the best for the root node

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On