Getting Error: no such column for values inserted - sqlite

I am just learning the first steps of SQLite and I am trying to create a small database and I always get the error message - Error: no such column: "Duisburg".
Can someone help me what I am doing wrong here?
Thanks a lot.
sqlite> CREATE TABLE Wohnort (PLZ int, Wohnort varchar(255), PRIMARY KEY (PLZ));
sqlite> INSERT INTO Wohnort (PLZ, Wohnort) VALUES (45472,“Mülheim“),(58674,“Köln),(47137,“Duisburg“);
Error: no such column: “Duisburg“

Related

SQLite SQL error or missing database (no such table)

Hi everyone I am having some problems with my SQLite database in my java program. I am trying to retrieve data from a couple of tables but it says my table doesn't exist. I have checked using DB Browser and it's definitely there, so I'm not sure what I'm doing wrong. This is the error I receive:
[SQLITE_ERROR] SQL error or missing database (no such table: staff_clocked_in.clock_in_time)
SELECT * FROM staff, staff_clocked_in.clock_in_time WHERE staff.staff_id = staff_clocked_in.staff_id;
I'm sure my tables exist and there is data in both tables, here is a screenshot of my db browser.
If it helps, this is how I have setup my tables:
STAFF:
CREATE TABLE IF NOT EXISTS staff (staff_id INTEGER PRIMARY KEY NOT NULL, first_name TEXT NOT NULL, last_name TEXT NOT NULL, job_title TEXT NOT NULL);
STAFF_CLOCKED_IN:
CREATE TABLE IF NOT EXISTS staff_clocked_in (staff_id INTEGER PRIMARY KEY NOT NULL REFERENCES staff(staff_id), clock_in_time DATETIME NOT NULL);
Can anyone see anything wrong with my query? I'm not good with databases so hopefully it's just something simple.
The error message is correct staff_clocked_in.clock_in_time is not a table.
You should use staff_clocked_in instead which is your table.
So the fixed query should look like
SELECT *
FROM staff, staff_clocked_in
WHERE staff.staff_id = staff_clocked_in.staff_id;

Insert returns error: (sub-select returns 6 columns - expected 1)

I have a table SIGHTINGS(NAME, PERSON, LOCATION, SIGHTED), and I'm trying to insert a new row into that table with the following query:
INSERT INTO SIGHTINGS (NAME, PERSON, LOCATION, SIGHTED)
VALUES ('Douglas dustymaiden', 'Person B', 'Double Mountain', '2005-11-28');
But it's returning this error:
[2017-12-04 17:08:18] [1] [SQLITE_ERROR] SQL error or missing database (sub-select returns 6 columns - expected 1)
I've looked up the correct syntax for sqlite inserts here, and from what I can tell, the insert is written correctly. Can someone tell me why it's throwing this error instead of doing the insert? I'm using DataGrip 2017 if that helps identify any issues.
EDIT:
Here's the trigger I added to the database. The insert works without the trigger.
CREATE TRIGGER SightingLocationError
BEFORE INSERT ON SIGHTINGS
FOR EACH ROW
WHEN NEW.LOCATION NOT IN FEATURES
BEGIN
SELECT RAISE(ABORT, 'Error: Insert into the SIGHTINGS table references location that is not found in the database.');
END;
WHEN NEW.LOCATION NOT IN FEATURES
The FEATURES table has six columns, so the database does not know how it should search for the location value.
Use an explicit subquery to return the column you want to use for this:
WHEN NEW.LOCATION NOT IN (SELECT xxx FROM FEATURES)

SQLlite: strange "Abort due to constraint violation"

I'm trying to rename a column of a table. I have a lot of tables with the word "couleur" and I renamed "manually" to "bulle".
I've successfully renamed main_groupecouleurs to main_groupebulles. Now i'm working on main_groupe. I'm trying to rename groupe_couleurs_id to groupe_bulles_id
The SQL is quite self-explaining:
BEGIN TRANSACTION;
DROP INDEX main_groupe_fc5cee5b;
CREATE TABLE main_groupe7e12
(
id INTEGER PRIMARY KEY NOT NULL,
description TEXT NOT NULL,
exemple TEXT,
groupe_bulles_id INTEGER DEFAULT NULL,
reference TEXT,
FOREIGN KEY (groupe_bulles_id) REFERENCES main_groupebulles(id)
DEFERRABLE INITIALLY DEFERRED
);
CREATE UNIQUE INDEX main_groupe_fc5cee5b ON main_groupe7e12 (groupe_bulles_id);
INSERT INTO main_groupe7e12(id, description, exemple, groupe_bulles_id, reference)
SELECT id, description, exemple, groupe_couleurs_id, reference
FROM main_groupe;
DROP TABLE main_groupe;
ALTER TABLE main_groupe7e12 RENAME TO main_groupe;
COMMIT;
When I run it, I get:
[SQLITE_CONSTRAINT] Abort due to constraint violation
(UNIQUE constraint failed: main_groupe7e12.groupe_bulles_id)
This means (I think I'm wrong here but I dont know what I'm missing) that it tries to insert some groupe_couleurs_id that are not in the referring table (= main_groupebulles). Thus I tried to see in the original table the problem:
SELECT * FROM main_groupe WHERE groupe_couleurs_id NOT IN (
SELECT id FROM main_groupebulles
);
I got no rows! What am I missing?
You have an UNIQUE index on your groupe_bulles_id column but based on the comments, there are a lot of valid duplicate values for that column coming from main_groupe.groupe_couleus_id and that causes the constraint violation.
Since having duplicate values is what you want, remove the UNIQUE from the CREATE UNIQUE INDEX ....

I am insert one table ERP_GatePass but ERP_GatePass_old table will be Refer,So mthis Error Occur

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_ERP_AssetIssue_ERP_GatePass". The conflict occurred in database "ERP_ASSETS_NFA", table "dbo.ERP_GatePass_Old", column 'GPID'.
The statement has been terminated.
In your table dbo.ERP_GatePass, it has a foreign key reference to another table. The FK works is it cannot have a value in that column that is not also in the primary key column of the referenced table.
You can Rectify or findout using this following way Source

Altering a column on SQLite after definition

I was following an SQLite tutorial where the goal is to create a simple student database from an UML diagram.
The first thing I did was copy your UML, then took a break. Upon return, I figured I'd get started from the UML while reloading your video, so the very first things I did was create the student and sex_type table as so:
sqlite> create table student(name VARCHAR(23),
...> sex CHARACTER(1),
...> id_number INTEGER PRIMARY KEY);
sqlite> create table sex_type(sex_id TEXT PRIMARY KEY, sex_type INTEGER);
But then I realized, I forgot to indicated that I want sex_id to be NOT NULL as well. I also forgot under the to ensure that Foreign Key(sex) references sex_type(sex_id).
I reviewed my SQL books, and recalled something known as the ALTER command. However, no matter how I slice it, I get something along these lines:
sqlite> alter table sex_type MODIFY column sex_id TEXT PRIMARY KEY NOT NULL;
Error: near "MODIFY": syntax error
sqlite> alter table sex_type CHANGE column sex_id TEXT PRIMARY KEY NOT NULL;**
Error: near "CHANGE": syntax error
sqlite> alter table sex_type drop sex_id;
Error: near "DROP": syntax error
Always with the same supposed syntax error. About the only thing that has worked tonight:
sqlite> alter table sex_type RENAME TO gender;
sqlite> alter table gender_id RENAME TO sex_type;
So what is this syntax error that I'm overlooking, because going by my books my syntax should be fine. Do I have to insert something into these columns before modification can be done (which admittedly, I haven't tried yet)? Or am I missing something obvious about the ALTER/MODIFY/CHANGE/DROP command(s)?
SQLite's support for ALTER TABLE is pretty limited, including only RENAME TO and ADD_COLUMN. You're getting syntax errors because you're issuing a command that's not supported.
If you don't have any data to lose, you might be better of dropping and recreating the table.
If you do have data to lose, you might be better off renaming the table and creating a replacement using INSERT with SELECT, as seen in this example.

Resources