ZecosMAX
ZecosMAX

Reputation: 213

SQLite specifying primary key

In short, i have this clause:

CREATE TABLE IF NOT EXISTS `journalData` 
(
    `JD_Key` INTEGER PRIMARY KEY AUTOINCREMENT, 
    `JD_Event_Key` INTEGER, 
    `JD_VarCount` INTEGER, 
    `JD_VarTypes` TEXT, 
    `JD_VarValues` TEXT,
    `JD_EventDate` TEXT 
);

INSERT INTO `journalData` 
VALUES (24, 0, '', '', '04.02.2023 20:26:18'); 

And following SQLite tutorials on AUTOINCREMENT (https://www.sqlitetutorial.net/sqlite-autoincrement/), it says the following:

Second, insert another row without specifying a value for the person_id column:

INSERT INTO people (first_name,last_name)
VALUES('William','Gate');

Implying, that you can add rows to the table, without having to specify primary key of a table, but I get this error:

Uncaught Error: table journalData has 6 columns but 5 values were supplied

What am I doing here wrong? I've tried to add single row with the key before mentioned insert. But I keep getting this error

Upvotes: 0

Views: 59

Answers (1)

ZecosMAX
ZecosMAX

Reputation: 213

I found a solution, it seems that error was somewhat misleading, i have to specify columns names.

though, if i specify all of the values in table it is not necessary to specify columns names, so because of that, during testing i assumed that syntax here is similar to MySQL, where from experience i remembered, that you don't have to specify names in this exact case.

so the following query worked for me.

INSERT INTO `journalData` 
(JD_Event_Key, JD_VarCount, JD_VarTypes, JD_VarValues, JD_Event_Date) 
VALUES (24,0,'','','04.02.2023 20:26:18');

Upvotes: 1

Related Questions