Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite: Howto Insert Foreign Key Values Into A Cross Reference Table
    primarykey
    data
    text
    <p>Given the following data table definitions in SQLite Version 3.7.5:</p> <pre><code>CREATE TABLE [Books] ( [Title] VARCHAR(125) NOT NULL, [YearPublished] INT, CONSTRAINT [CK_YearPublished] CHECK(YearPublished &gt;= 1400)); CREATE TABLE [People] ( [FirstName] VARCHAR(25) NOT NULL, [LastName] VARCHAR(45) NOT NULL, [MiddleName] VARCHAR(25), CONSTRAINT [UQ_PersonName] UNIQUE([FirstName], [LastName], [MiddleName])); CREATE TABLE [BooksAuthorsXRef] ( [BookID] INT NOT NULL CONSTRAINT [FK_BookID] REFERENCES [Books]([rowid]), [PersonID] INT NOT NULL CONSTRAINT [FK_PersonID] REFERENCES [People]([rowid])); </code></pre> <p>What SQL command can I use to populate the BookID and PersonID field values in the BooksAuthorsXRef data table to use the values for the rowid for a specific Title in the Books table to be associated with the rowid in the Persons table for a given LastName, FirstName, and MiddleName set of values?</p> <p>I've already populated the Books table with one record;</p> <pre><code>INSERT INTO Books VALUES ('Stingray Shuffle', 2003); </code></pre> <p>And, the Persons table has been populated with the following record:</p> <pre><code>INSERT INTO People (LastName, FirstName) VALUES ('Dorsey', 'Tim') </code></pre> <p>What SQL command would I use in SQLite to define that Tim Dorsey (Persons rowid = 1) is the author of the book entitled "Stingray Shuffle" in the Books table (Books rowid = 1)?</p> <p>Also, based on the data table definitions, are any changes needed to make adding and changing Books and Persons cross reference records in the BooksAuthorsXRef data table more managable and easier while maintaining some degree of referential integrity?</p> <p>Thank you in advance for your time, help and patience. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload