

We only need to make one change in one place. So that if we ever need to change the data, They also believe that this key should be separate from the data itself, Person.id is the primary key in the Person table,Įvery table should have a well-defined primary key. That identifies a unique record in another table.Ī foreign key is the primary key of one table That uniquely identifies each record in a table.Ī foreign key is a value (or combination of values) from one table We can tell which records from Site, Visited, and Survey To select the three columns we actually want The result would inherit a field called id If we joined the Person and Visited tables, We do this because tables can have fields with the same name,Īnd we need to be specific which ones we’re talking about. Notice that we used Table.field to specify field names That combined information about two different sites, There are differences in how they affect outer joins,īut that’s beyond the scope of this lesson. JOIN Visited ON Site.name = Visited.site Īnd for all the queries in this lesson you can use them interchangeably. We’re only interested in combinations that have the same site name, It has no way of knowing whether they do or not until we tell it how. įigure out if the records being joined have anything to do with each other. The join’s output has 24 records (3 * 8 = 24). It joins each record of one table with each record of the other table Suppose we want to select all sites that lie within 48 degrees of the equator. Or write a small program to generate ten thousand random (but plausible) records We could run it against a sample of ten thousand, Instead of trying our queries against an actual database of 20 million Australians, Or to fill a small database with synthesized records. To put a subset of data in a temporary database The best way to achieve a quick turnaround is often We started with something simple that did part of what we wanted,įor complex queries it’s often the only strategy - butĪnd on us recognizing the right answer when we get it. What we have just done is how most people “grow” their SQL queries. Not to the entire rows as they are being processed. SELECT DISTINCT person, quant FROM Survey WHERE person = 'lake' OR person = 'roe' ĭISTINCT is applied to the values displayed in the chosen columns, If you saved it at your Desktop you should use Notice that three entries - one in the Visited table,Īnd two in the Survey table - don’t contain any actualĭata, but instead have a special -null- entry:Ĭhange the working directory to the one where you saved survey.db. The values are rad, sal, and temp referring to ‘radiation’, ‘salinity’ and ‘temperature’, respectively. The field quant is short for quantity and indicates what is being measured. Survey: The measurements taken at each precise location on these sites. In order to use the SQLite commands interactively, we need toĮnter into the SQLite console. So it is possible to move information from one to another. So a database created with one cannot be used directly by another.Ĭan import and export data in a variety of formats like. SQL but each stores data in a different way,

IBM DB2, PostgreSQL, MySQL, Microsoft Access, and SQLite - understand We will only look at a handful of queries,īut that handful accounts for most of what scientists do. SQL provides hundreds of different ways to analyze and recombine data. Which stands for “Structured Query Language”. Queries are written in a language called SQL, That we can then use as a starting point for further queries. The database manager does whatever lookups and calculations the query specifies, We put formulas into cells to calculate new values based on old ones.Ī program that manipulates the database for us. Is a way to store and manipulate information.Įach table has columns (also known as fields) that describe the data,Īnd rows (also known as records) which contain the data. Write a query to select all values for specific fields from a single table. Explain the difference between a table, a record, and a field.Įxplain the difference between a database and a database manager.
