{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Creating and Modifying Data" ] }, { "cell_type": "markdown", "metadata": { "cell_tags": [ "objectives" ] }, "source": [ "#### Objectives\n", "\n", "* Write queries that creates tables.\n", "* Write queries to insert, modify, and delete records." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So far we have only looked at how to get information out of a database,\n", "both because that is more frequent than adding information,\n", "and because most other operations only make sense\n", "once queries are understood.\n", "If we want to create and modify data,\n", "we need to know two other pairs of commands.\n", " \n", "The first pair are `create table` and `drop table`.\n", "While they are written as two words,\n", "they are actually single commands.\n", "The first one creates a new table;\n", "its arguments are the names and types of the table's columns.\n", "For example,\n", "the following statements create the four tables in our survey database:\n", "\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", "~~~\n", "drop table Survey;\n", "~~~\n", "\n", "Be very careful when doing this:\n", "most databases have some support for undoing changes,\n", "but it's better not to have to rely on it.\n", " \n", "Different database systems support different data types for table columns,\n", "but most provide the following:\n", "\n", "
| integer | a signed integer |
| real | a floating point number |
| text | a character string |
| blob | a \"binary large object\", such as an image |