title: SQLite3 how to create an insert statement for many-to-many relationship?
body: <p>Let's say you have three basic tables that implement a many-to-many relationship between tasks and categories:</p>
  
  <pre><code>CREATE TABLE task(
      id INTEGER AUTOINCREMENT PRIMARY KEY NOT NULL,
      name INTEGER NOT NULL,
      description INTEGER NOT NULL
  );
  CREATE TABLE category(
      id INTEGER AUTOINCREMENT PRIMARY KEY NOT NULL,
      name TEXT NOT NULL
  );
  CREATE TABLE task_category(
      task_id INTEGER,
      category_id INTEGER,
  );
  </code></pre>
  
  <p>If I want to insert into my database a task named "wrote script" with some description "I wrote a python script." that is associated with categories "python" and "scripting", how do I do so? Assume that the python and scripting categories already exist in the database. </p>
  
  <p>I took a look at this question: <a href="https://stackoverflow.com/questions/6935620/sqlite-many-to-many-relationship">SQLite many-to-many relationship?</a></p>
  
  <p>It seems like some implementation of foreign keys might be useful but I still don't know what the INSERT statement would look like.</p>
  
  <p>My best attempt would be to insert the task into the task table, then do a select to get the task I just inserted back with its id, then link up that id to the categories in the task_category table manually. This doesn't seem like a very effective way of doing this.</p>
  
  <p>What is the standard way of inserting a record into a sqlite database and linking it up to a many-to-many relationship?</p>