85 |
86 |
87 |
88 | **Person**: People who took readings, `id` being the unique identifier for that person.
89 |
90 | | id | personal | family |
91 | | --------- | --------- | ---------- |
92 | | dyer | William | Dyer |
93 | | pb | Frank | Pabodie |
94 | | lake | Anderson | Lake |
95 | | roe | Valentina | Roerich |
96 | | danforth | Frank | Danforth |
97 |
98 | **Site**: Locations of the `sites` where readings were taken.
99 |
100 | | name | lat | long |
101 | | --------- | --------- | ---------- |
102 | | DR-1 | \-49.85 | \-128.57 |
103 | | DR-3 | \-47.15 | \-126.72 |
104 | | MSK-4 | \-48.87 | \-123.4 |
105 |
106 | **Visited**: Specific identification `id` of the precise locations where readings were taken at the sites and dates.
107 |
108 | | id | site | dated |
109 | | --------- | --------- | ---------- |
110 | | 619 | DR-1 | 1927-02-08 |
111 | | 622 | DR-1 | 1927-02-10 |
112 | | 734 | DR-3 | 1930-01-07 |
113 | | 735 | DR-3 | 1930-01-12 |
114 | | 751 | DR-3 | 1930-02-26 |
115 | | 752 | DR-3 | \-null- |
116 | | 837 | MSK-4 | 1932-01-14 |
117 | | 844 | DR-1 | 1932-03-22 |
118 |
119 |
120 |
121 |
122 |
123 | **Survey**: The measurements taken at each precise location on these sites. They are identified as `taken`. The field `quant` is short for quantity and indicates what is being measured. The values are `rad`, `sal`, and `temp` referring to 'radiation', 'salinity' and 'temperature', respectively.
124 |
125 | | taken | person | quant | reading |
126 | | --------- | --------- | ---------- | ------- |
127 | | 619 | dyer | rad | 9\.82 |
128 | | 619 | dyer | sal | 0\.13 |
129 | | 622 | dyer | rad | 7\.8 |
130 | | 622 | dyer | sal | 0\.09 |
131 | | 734 | pb | rad | 8\.41 |
132 | | 734 | lake | sal | 0\.05 |
133 | | 734 | pb | temp | \-21.5 |
134 | | 735 | pb | rad | 7\.22 |
135 | | 735 | \-null- | sal | 0\.06 |
136 | | 735 | \-null- | temp | \-26.0 |
137 | | 751 | pb | rad | 4\.35 |
138 | | 751 | pb | temp | \-18.5 |
139 | | 751 | lake | sal | 0\.1 |
140 | | 752 | lake | rad | 2\.19 |
141 | | 752 | lake | sal | 0\.09 |
142 | | 752 | lake | temp | \-16.0 |
143 | | 752 | roe | sal | 41\.6 |
144 | | 837 | lake | rad | 1\.46 |
145 | | 837 | lake | sal | 0\.21 |
146 | | 837 | roe | sal | 22\.5 |
147 | | 844 | roe | rad | 11\.25 |
148 |
149 |
150 |
151 |
152 |
153 | Notice that three entries --- one in the `Visited` table,
154 | and two in the `Survey` table --- don't contain any actual
155 | data, but instead have a special `-null-` entry:
156 | we'll return to these missing values
157 | [later](05-null.md).
158 |
159 | ::::::::::::::::::::::::::::::::::::::::: callout
160 |
161 | ## Checking If Data is Available
162 |
163 | On the shell command line,
164 | change the working directory to the one where you saved `survey.db`.
165 | If you saved it at your Desktop you should use
166 |
167 | ```bash
168 | $ cd Desktop
169 | $ ls | grep survey.db
170 | ```
171 |
172 | ```output
173 | survey.db
174 | ```
175 |
176 | If you get the same output, you can run
177 |
178 | ```bash
179 | $ sqlite3 survey.db
180 | ```
181 |
182 | ```output
183 | SQLite version 3.8.8 2015-01-16 12:08:06
184 | Enter ".help" for usage hints.
185 | sqlite>
186 | ```
187 |
188 | that instructs SQLite to load the database in the `survey.db` file.
189 |
190 | For a list of useful system commands, enter `.help`.
191 |
192 | All SQLite-specific commands are prefixed with a `.` to distinguish them from SQL commands.
193 |
194 | Type `.tables` to list the tables in the database.
195 |
196 | ```sql
197 | .tables
198 | ```
199 |
200 | ```output
201 | Person Site Survey Visited
202 | ```
203 |
204 | If you had the above tables, you might be curious what information was stored in each table.
205 | To get more information on the tables, type `.schema` to see the SQL statements used to create the tables in the database. The statements will have a list of the columns and the data types each column stores.
206 |
207 | ```sql
208 | .schema
209 | ```
210 |
211 | ```output
212 | CREATE TABLE Person (id text, personal text, family text);
213 | CREATE TABLE Site (name text, lat real, long real);
214 | CREATE TABLE Survey (taken integer, person text, quant text, reading real);
215 | CREATE TABLE Visited (id integer, site text, dated text);
216 | ```
217 |
218 | The output is formatted as \<**columnName** *dataType*\>. Thus we can see from the first line that the table **Person** has three columns:
219 |
220 | - **id** with type *text*
221 | - **personal** with type *text*
222 | - **family** with type *text*
223 |
224 | Note: The available data types vary based on the database manager - you can search online for what data types are supported.
225 |
226 | You can change some SQLite settings to make the output easier to read.
227 | First,
228 | set the output mode to display left-aligned columns.
229 | Then turn on the display of column headers.
230 |
231 | ```sql
232 | .mode column
233 | .header on
234 | ```
235 |
236 | Alternatively, you can get the settings automatically by creating a `.sqliterc` file.
237 | Add the commands above and reopen SQLite.
238 | For Windows, use `C:\Users\