0

I have a .sql file called create.sql. It consists of the following lines:

drop table if exists Items;
drop table if exists Auctions;
create table Items(...);
create table Auctions(...);

When I run:

sqlite3 test < create.sql

It crashes and says, "Error: near line 1: near "drop": syntax error" Any thoughts?

user3562967
  • 151
  • 3
  • 12
  • Check out [this link](http://stackoverflow.com/questions/167576/check-if-table-exists-in-sql-server) – programmer43229 Oct 20 '14 at 17:05
  • @programmer43229 That has nothing to do with this question. – CL. Oct 20 '14 at 18:14
  • How exactly did you create and save that .sql file? – CL. Oct 20 '14 at 18:14
  • Sure it does. The link shows how they determine if a table exists before they try to select from it. You need to change their ` SELECT 1 AS ...` to your `DROP TABLE ...`. Okay, that's for SQL. I don't know about sqlite 3 & terminal. – programmer43229 Oct 20 '14 at 18:18

1 Answers1

0

I just tried this SQL Fiddle, there is no problem with the SQL syntax

The problem seems to be with the way the file is created and looks to be platform specific

if you are using Notepad++ or other editors, try converting the file to Unix style EOL i.e. \n, the file might be having \r\n which sqllit3 is complaining about.

radar
  • 13,270
  • 2
  • 25
  • 33