CREATE TABLE in SQL using Command Line

Screen Link:
SQL Database Relations And Normalization | Dataquest

My Code:

home/dq$ sqlite3 chinook.db
#  sqlite3> CREATE TABLE wishlist (
#      ...> wishlist_id INTEGER PRIMARY KEY,
#      ...> customer_id INTEGER,
#      ...> FOREIGN KEY (customer_id) REFERENCES customer(customer_id)
#      ......> name TEXT );

I get an error of the type : Error : near “name” : syntax error

  1. I would like to ask why is there an error when i execute my code. There is not much difference compared to DQ’s code given below. Is it because foreign key code should be in last row ?

  2. Second query is how can I edit the executed code. Do i need to type in everything again in SQL ? I can’t seem to edit or copy the code


I haven’t done this lesson yet so I can’t speak from experience but I believe the reason you’re getting an error is because you’re missing a comma before name TEXT.

EDIT_1: I tested my theory and it failed…it appears name TEXT needs to come before FOREIGN KEY. Perhaps a more experienced SQL user can help explain this.

Have you tried pressing ↑ on your keyboard to display the last command?

EDIT_1: This does not work as it does in other command line lessons; it appears COPY / PASTE using Ctrl + Ins / Shift + Ins is the only way to speed things up :slightly_frowning_face:

1 Like

If I recall correctly, that’s right and that’s all there is to it. It’s just how the syntax works.

1 Like

You can’t edit the code in this instance, but it’s not about SQL. It’s about the environment you’re coding in. It’s typical for shells to not allow to edit already submitted lines of code.

Thanks Bruno, Mike. Being a newbie I will take any answer and rest can test along the way !

Part of the reason I am asking questions is to help future coders. DQ’s SQL modules seems to be missing community interaction , seems like people only love Python here !