"For example,\n",
"the following statements create the four tables in our survey database:\n",
"\n",
- " create table Person(ident text, personal text, family text);\n",
- " create table Site(name text, lat real, long real);\n",
- " create table Visited(ident integer, site text, dated text);\n",
- " create table Survey(taken integer, person text, quant real, reading real);\n",
+ "~~~\n",
+ "create table Person(ident text, personal text, family text);\n",
+ "create table Site(name text, lat real, long real);\n",
+ "create table Visited(ident integer, site text, dated text);\n",
+ "create table Survey(taken integer, person text, quant real, reading real);\n",
+ "~~~\n",
"\n",
"We can get rid of one of our tables using:\n",
- " \n",
- " drop table Survey;\n",
+ "\n",
+ "~~~\n",
+ "drop table Survey;\n",
+ "~~~\n",
"\n",
"Be very careful when doing this:\n",
"most databases have some support for undoing changes,\n",
"we can specify several kinds of constraints on its columns.\n",
"For example,\n",
"a better definition for the `Survey` table would be:\n",
- " \n",
- " create table Survey(\n",
- " taken integer not null, -- where reading taken\n",
- " person text, -- may not know who took it\n",
- " quant real not null, -- the quantity measured\n",
- " reading real not null, -- the actual reading\n",
- " primary key(taken, quant),\n",
- " foreign key(taken) references Visited(ident),\n",
- " foreign key(person) references Person(ident)\n",
- " );\n",
+ "\n",
+ "~~~\n",
+ "create table Survey(\n",
+ " taken integer not null, -- where reading taken\n",
+ " person text, -- may not know who took it\n",
+ " quant real not null, -- the quantity measured\n",
+ " reading real not null, -- the actual reading\n",
+ " primary key(taken, quant),\n",
+ " foreign key(taken) references Visited(ident),\n",
+ " foreign key(person) references Person(ident)\n",
+ ");\n",
+ "~~~\n",
"\n",
"Once again,\n",
"exactly what constraints are avialable\n",
"`insert` and `delete`.\n",
"The simplest form of `insert` statement lists values in order:\n",
"\n",
- " insert into Site values('DR-1', -49.85, -128.57);\n",
- " insert into Site values('DR-3', -47.15, -126.72);\n",
- " insert into Site values('MSK-4', -48.87, -123.40);\n",
+ "~~~\n",
+ "insert into Site values('DR-1', -49.85, -128.57);\n",
+ "insert into Site values('DR-3', -47.15, -126.72);\n",
+ "insert into Site values('MSK-4', -48.87, -123.40);\n",
+ "~~~\n",
"\n",
"We can also insert values into one table directly from another:\n",
- " \n",
- " create table JustLatLong(lat text, long TEXT);\n",
- " insert into JustLatLong select lat, long from site;\n",
+ "\n",
+ "~~~\n",
+ "create table JustLatLong(lat text, long TEXT);\n",
+ "insert into JustLatLong select lat, long from site;\n",
+ "~~~\n",
"\n",
"Deleting records can be a bit trickier,\n",
"because we have to ensure that the database remains internally consistent.\n",
"For example,\n",
"once we realize that Frank Danforth didn't take any measurements,\n",
"we can remove him from the `Person` table like this:\n",
- " \n",
- " delete from Person where ident = \"danforth\";\n",
+ "\n",
+ "~~~\n",
+ "delete from Person where ident = \"danforth\";\n",
+ "~~~\n",
"\n",
"But what if we removed Anderson Lake instead?\n",
"Our `Survey` table would still contain seven records\n",
" containing temperature readings by Robert Olmstead,\n",
" which is formatted like this:\n",
"\n",
- " ```\n",
+ " ~~~\n",
" Taken,Temp\n",
" 619,-21.5\n",
" 622,-15.5\n",
- " ```\n",
+ " ~~~\n",
"\n",
" Write a small Python program that reads this file in\n",
" and prints out the SQL `insert` statements needed\n",