tags:

views:

365

answers:

3

New to SQLite so I don't know what I'm doing wrong. I'm just getting an error saying:

SQLSTATE[HY000]: General error: 1 near "CREATE": syntax error

Here's my SQL:

CREATE TABLE users (
  id INTEGER NOT NULL PRIMARY KEY,
  date_created DATETIME NOT NULL,
  date_updated DATETIME NOT NULL,
  username VARCHAR(32) NOT NULL,
  password VARCHAR(32) NOT NULL,
  role VARCHAR(32) NOT NULL DEFAULT 'member',
  first_name VARCHAR(50) NOT NULL,
  last_name VARCHAR(50) NOT NULL,
  email VARCHAR(128) NOT NULL
)

CREATE TABLE subscribers (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR(40) DEFAULT NULL,
  email VARCHAR(255) NOT NULL UNIQUE
)

CREATE TABLE weekly_download (
  id INTEGER NOT NULL PRIMARY KEY,
  filename TEXT NOT NULL,
  download_date DATE NOT NULL,
  body TEXT
)
+5  A: 

put a semicolon after each statement.

CREATE TABLE ( ... ) ;
CREATE TABLE ( ... ) ;
marcc
+2  A: 

Don't forget semi-colons!

clownbaby
+2  A: 

Start with simple statements using the sqlite3 CLI.

Then, if you forget a ;, you will get quick feedback and can build up to more complex SQL.

$ sqlite3 /tmp/test.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> create table badsyntax;
SQL error: near ";": syntax error
sqlite> create table abc (x,y);
sqlite>
DigitalRoss