skip to Main Content
CREATE TABLE users (
  user_id INTEGER PRIMARY KEY AUTOINCREMENT
  name TEXT NOT NULL
  );

(it’s located at the AUTOINCREMENT.)

I’m so confused with that line. can anyone help me understand? I’m new in here and my lecturer told me to download this and just do a test run which should work but it doesn’t.

2

Answers


  1. you are missing comma after the AUTOINCREMENT to separate definitions of columns between each other. try same code just with "," after first column definition. try this code:

    CREATE TABLE users (
    user_id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL
    );

    Login or Signup to reply.
  2. In MySQL, use AUTO_INCREMENT, not AUTOINCREMENT.

    The underscore character (_) is necessary in MySQL.

    SQLite, a different database product, uses the word AUTOINCREMENT (with no underscore).

    You should understand as you start learning SQL, that each brand that implements SQL has their own variations. They don’t always implement the same features or the same syntax. You should familiarize yourself with the manual for the exact brand and version of product you use. If you switch brands, or try to use code intended for a different brand, you probably have to make some edits.

    Also you need a comma between each column definition, as the other answer mentions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search