Quote:
Originally Posted by Booocubs
private static final string DATABASE_CREATE = "create table todo (_id integer primary key autoincrement, "
+ "category text not null, summary text not null, description text not null);";
|
Let's start by reformatting that SQL statement` so it's easier to see the parts. I also capitalised the SQL keywords to distinguish them from your identifiers. SQL keywords are not case-sensitive (table is Table is TABLE), unlike Java.
Code:
CREATE TABLE todo
(
_id INTEGER PRIMARY KEY AUTOINCREMENT,
category TEXT NOT NULL,
summary TEXT NOT NULL,
description TEXT NOT NULL
);
This is an example of a CREATE TABLE statement. The full syntax and details of this statement in sqlite3 is documented here:
SQLite Query Language: CREATE TABLE.
This example creates a table called todo.
The clauses between the parentheses describe the table. In this example you have 4 column definitions.
Each column definition starts with a column name. This is optionally followed by the name of a
datatype. Finally there are zero or more
column constraints.
The first clause defines a column called _id that holds integer values. There are two column constraints. First it defines the _id column to be the table's
primary key. Next it defines that the column will
auto increment.
The next three clauses define columns called category, summary and description. These columns are all defined as holding text. Each has a single column constraint, NOT NULL. This precludes any of these columns from being NULL. If you try to insert a row with null for any of these column, sqlite3 will raise an error.
Note that PRIMARY KEY implies NOT NULL. So the _id column is also precluded from storing NULL.
If you are new to SQL itself, maybe this online SQL tutorial might help.
http://www.sqlcourse.com/