Andrew
Andrew

Reputation: 238667

Error in my SQLite syntax

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
)

Upvotes: 5

Views: 8188

Answers (3)

DigitalRoss
DigitalRoss

Reputation: 146053

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> 

Upvotes: 4

danjarvis
danjarvis

Reputation: 10190

Don't forget semi-colons!

Upvotes: 3

marcc
marcc

Reputation: 12399

put a semicolon after each statement.

CREATE TABLE ( ... ) ;
CREATE TABLE ( ... ) ;

Upvotes: 11

Related Questions