0

I have a file called schema.sql, which looks like this:

drop table if exists codes;
create table paste_codes (
    id integer primary key autoincrement,
    codetitle string not null,
    codebody string not null,
    pub_date string not null
)

Is there any way I can tel sqlite3 to read it from this file and create the database for me? Something like cat schema.sql > sqlite3 /tmp/database.db?

Thanks

  • Just so you know: The SQL file instructs the creation of a table, not a database. There's a big difference. – Simon Forsberg Jun 09 '12 at 18:37
  • 1
    Might want to take a look at http://stackoverflow.com/questions/489277/script-to-convert-mysql-dump-sql-file-into-format-that-can-be-imported-into-sqli (don't know of an easier way) – Exupery Jun 09 '12 at 18:37
  • Oh, I thought a simple way of piping would do the job, a whole sh code! Thanks buddies! Simon, thanks, I will take a better look on that! –  Jun 09 '12 at 18:45

1 Answers1

0

I got this fixed. I changed the code to:

drop table if exists paste_code;
create table paste_code (
    id integer primary key autoincrement,
    codetitle string not null,
    codebody string not null,
    pub_date string not null
);

and I simply:

$ sqlite3 /tmp/database.db < schema.sql

And everything started working perfect!