Anita Dick Anita Dick - 1 year ago 108
SQL Question

Creating Databases in SQLite

We were asked to create a database in sqlite3 and then create a table in it. I used this command:

$sqlite3 me5.db

and tried to create a table with this statement:

CREATE TABLE me5.petID(pet id PRIMARY KEY int(3), pet name varchar(10), pet type varchar(10), pet age int(3));

but it says that:

ERROR: near "CREATE" : syntax error

What could I have possible done wrong? Thanks.

Answer Source

try this

CREATE TABLE petID(pet_id int(3) PRIMARY KEY, pet_name varchar(10), pet_type varchar(10), pet_age int(3));
  1. you dont have to specify the database name because you're already using it after the command sqlite3 me5.db.
  2. you have spaces in the names of the fields, which is not allowed. so i've put underscores instead of spaces.
  3. use PRIMARY KEY after int(3)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download