Igor Tandetnik wrote:
> 
> "alp" <[EMAIL PROTECTED]> wrote in
> message news:[EMAIL PROTECTED]
>> I have to tables(TBL_OBJECTS, TBL_TAGS) and I want to use the ROWID
>> of the last inserted row from table TBL_OBJECTS to insert a new row
>> in TBL_TAGS table with the ID_OBJECT foreign key set to the ROWID
>> value from the precedent table.
>>
>> INSERT INTO TBL_OBJECTS
>>  (DATA,
>>  PATH)
>>  VALUES ('val1', 'val2');
>>
>>  INSERT INTO TBL_TAGS
>>  (ID_TAG_TYPE,
>>  ID_OBJECT,
>>  TAG_DATA)
>>  VALUES (1, 2, 'a'); --doesn't count what value is inserted for
>> ID_OBJECT as it will be changed in the next statement
> 
> Why not just
> 
> INSERT INTO TBL_TAGS
>   (ID_TAG_TYPE,
>   ID_OBJECT,
>   TAG_DATA)
>   VALUES (1, last_insert_rowid(), 'a');
> 
> See http://sqlite.org/lang_corefunc.html
> 
> Igor Tandetnik 
> 
> 
> 
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 
> 

Thanks a lot Igor, didn't knew about the existence of last_insert_rowid()
function.
-- 
View this message in context: 
http://www.nabble.com/How-to-use-the-ROWID-of-the-last-inserted-row-for-FK-insert-into-other-tables--tp19085514p19087337.html
Sent from the SQLite mailing list archive at Nabble.com.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to