I am trying to run this in Terminal but it keeps giving me syntax error when I type .schema. I even copied the code from the book and see if I type anything wrong but still syntax error. And I am really confused about the command line part for SQL. It was easy to understand when I did it with learning python the hard way. Maybe I need more practice?
This is the code in Atom:
CREATE TABLE person (
id INTEGER PRIMARY KEY,
first_name TEXT,
last_name TEXT,
age INTEGER
);
CREATE TABLE pet (
id INTEGER PRIMARY KEY,
name TEXT,
breed TEXT,
age INTEGER,
dead INTEGER
);
Hi @Parixiat I donât think there is anything wrong with the SQL table creations listed above as you successful create the db from them.
You must have a syntax error in your queries in ex1.sql âsomewhere nearâ parenthesis (as the error is telling you). Check the line before or after any such parenthesis and ensure you always have opening and closing bracket pairs.
As for command line usage, its not vastly different than what you did in Python. You are calling a program and specifying a file to run, so in this example; run file ex1 (which is of type sql) and use sqlite to execute it.
Or remember when you opened pythonâs interactive prompt, itâs the same with sqlite. You can open it to play around with an interactive prompt (âsqlite>â). Here you are using the sqlite software and asking it to show you the .schema from ex1.sql.
And⌠I think thatâs your error. You probably want to open the db file, not the sql file! The sql file specifies the database that you then build with: