<p>This homework gives pracice with the most important aspects of SQL we covered.</p>
<h2>Assignment</h2>
<p>
Write commands to implement the database represented in the class diagram below in SQLite. You can use <ahref="https://sql.js.org/examples/GUI/">this SQL interpreter</a> or a local installation of SQLite, at your discretion. You will be submitting <strong>all of the SQL commands</strong> to implement the database, as described below.
</p>
<h2>Database design</h2>
<p>
<imgsrc="class diagram.png"width="550"><br>
Implement the database as pictured above. Note that the many-to-many relationship between Species and Regions will require a junction table. Write the following in SQL (invent data as necessary).
<ul>
<li>Create all tables
<ul>
<li>Use a primary key for each table (a junction table should get a two-column primary key if each pairing should happen at most once)</li>
<li>Declare foreign key constraints where appropriate (recall that you will want to issue the <code>PRAGMA foreign_keys = ON;</code> command before using foreign keys)</li>
<li>Delete a given spotter by ID and NULL out his/her ID in all of the associated sightings. Do this as a transaction and specify OR ROLLBACK for the UPDATE command therein. I would do the same for the DELETE command, but OR ROLLBACK is not supported for DELETE in Sqlite because foreign key constraints are not checked by Sqlite's OR ROLLBACK algorithm, and - as far as I can tell - <ahref="https://www.sqlite.org/lang_conflict.html">none of the other checks performed are relevant to DELETE</a>.</li>
<p>Note that in real life, it would likely be useful to have a geospatial index on latitude and longitude. SQLite doesn't support this, but there are <ahref="https://www.gaia-gis.it/fossil/libspatialite/index">add-ons</a> and <ahref="https://www.linkedin.com/pulse/what-geospatial-index-gaurav-pandey">workarounds</a> (though that is not required for this assignment).</p>