Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learn SQL the Hard Way - Exercise 3 - Inserting Data - cannot find file

Tags:

sql

sqlite

echo

Here is a SQL class I'm taking online. I think I'm confused more on the setup of the SQL files rather than the SQL itself. The INSERT statements are straightforward.

INSERT INTO person (id, first_name, last_name, age)
    VALUES (0, "Zed", "Shaw", 37);

INSERT INTO pet (id, name, breed, age, dead)
    VALUES (0, "Fluffy", "Unicorn", 1000, 0);

INSERT INTO pet VALUES (1, "Gigantor", "Robot", 1, 1);

In my Windows command prompt, this runs fine.

C:\SQLite> sqlite3 ex3.db < ex2.sql

In my ex2.sql, he seems to suggest combining CREATE statements from Lesson 2, with the INSERT statements to create a new ex3.db. It seems to work - no errors.

Then he says to run the following statement to display my INSERT statements.

C:\SQLite> sqlite3 -echo ex3.db < ex3.sql

Instead of displaying the INSERT statements, I get the following error:

The system cannot find the file specified.

Is there an error in the lesson? I don't think he ever asked the user to create an ex3.sql file?

So assuming this was a typo, I changed the echo statement to use ex2.sql, since this is the file that contains my INSERT statements.

I get the following errors when I use sqlite3 -echo ex3.db < ex2.sql

Error: near line 1: table person already exists
Error: near line 8: table pet already exists
Error: near line 16: table person_pet already exists
INSERT INTO person (id, first_name, last_name, age)
        VALUES (0, "Zed", "Shaw", 37);
Error: near line 21: PRIMARY KEY must be unique
INSERT INTO pet (id, name, breed, age, dead)
    VALUES (0, "Fluffy", "Unicorn", 1000, 0);
Error: near line 24: PRIMARY KEY must be unique
INSERT INTO pet VALUES (1, "Gigantor", "Robot", 1, 1);
Error: near line 27: PRIMARY KEY must be unique

Is there a typo in the lesson? Was I supposed to create an ex3.sql file with ONLY the INSERT statements by themselves?

like image 366
StacyM Avatar asked Dec 04 '25 05:12

StacyM


1 Answers

The error message was trying to tell you that ex3.sql could not be found.

You are supposed to use the old ex2.sql file to create the tables, and to put the new INSERT statements into ex3.sql.

like image 129
CL. Avatar answered Dec 07 '25 01:12

CL.