You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.9 KiB
79 lines
3.9 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Homework 1: Bird database</title>
|
|
<link rel="stylesheet" href="../style.css">
|
|
<style>
|
|
img {
|
|
border: 1px solid black;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="page">
|
|
<h1>Homework 1: Bird database</h1>
|
|
<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 <a href="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>
|
|
<img src="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>Declare an index for the SpotterID foreign key column of Sightings</li>
|
|
</ul>
|
|
</li>
|
|
<li>Fill tables with initial data
|
|
<ul>
|
|
<li>Put in at least 6 actual bird species</li>
|
|
<li>Put in the regions: Midwest, Northeast, South, West</li>
|
|
<li>Put in 3 spotters (one of them should be JD - the Math/CS department head who is a birder)</li>
|
|
<li>Put in at least 4 sightings; at least two of them should be by JD</li>
|
|
<li>Associate each bird with the regions it actually lives in</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
Include the following query commands:
|
|
<ul>
|
|
<li>Select the lat, lon, date, and species name for each sighting made by JD.</li>
|
|
<li>Pick some specific bird species and write a query that selects all region names in which it lives.</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
Include the following update command:
|
|
<ul>
|
|
<li>Update some bird's name to its scientific name.</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
Include the following delete command:
|
|
<ul>
|
|
<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 - <a href="https://www.sqlite.org/lang_conflict.html">none of the other checks performed are relevant to DELETE</a>.</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</p>
|
|
|
|
<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 <a href="https://www.gaia-gis.it/fossil/libspatialite/index">add-ons</a> and <a href="https://www.linkedin.com/pulse/what-geospatial-index-gaurav-pandey">workarounds</a> (though that is not required for this assignment).</p>
|
|
|
|
<hr>
|
|
<p>Submit a text document with all of your SQL commands in Educat, by November 13, 2024.</p>
|
|
</div>
|
|
|
|
|
|
</body>
|
|
|
|
</html> |