title: How can I access the last inserted row ID within a SQL script?
body: <p>I'm using SQLite, and I have a table for properties, and a table for sub-properties.  Each sub-property points to its parent using the fkPropertyId column.  Right now, to create the initial database, I've got a script that looks something like this:</p>
  
  <pre><code>INSERT INTO property VALUES(1,.....);
  INSERT INTO property VALUES(2,.....);
  INSERT INTO property VALUES(3,.....);
     INSERT INTO subproperty VALUES(1,.....,3);
     INSERT INTO subproperty VALUES(2,.....,3);
     INSERT INTO subproperty VALUES(3,.....,3);
  INSERT INTO property VALUES(4,.....);
  </code></pre>
  
  <p>Now, I want to get rid of the hard-coded rowId, so it would be something like:</p>
  
  <pre><code>INSERT INTO property VALUES(NULL,.....);
  INSERT INTO property VALUES(NULL,.....);
  INSERT INTO property VALUES(NULL,.....);
     INSERT INTO subproperty VALUES(NULL,.....,X);
     INSERT INTO subproperty VALUES(NULL,.....,X);
     INSERT INTO subproperty VALUES(NULL,.....,X);
  INSERT INTO property VALUES(NULL,.....);
  </code></pre>
  
  <p>Where x refers to the last inserted rowId in the property table.  Right now, that's</p>
  
  <pre><code>(SELECT MAX(rowId) FROM property)
  </code></pre>
  
  <p>Is there any better (and more technically accurate) way to write this script?</p>