Lazarus

Programming => Databases => Topic started by: Pe3s on September 25, 2022, 05:21:23 pm

Title: [SOLVED] SQLite delete a record with no visible ID
Post by: Pe3s on September 25, 2022, 05:21:23 pm
Hello forum members, we have a database: id, Name, Surname, Age, City.
we ask 'SELECT Name, Surname, Age, City FROM table'. How can you, for example, delete a record if we do not have access to id?
Title: Re: SQLite delete a record with no visible ID
Post by: rvk on September 25, 2022, 05:33:52 pm
You can delete with a more elaborate WHERE clause like
delete from table where name:='a' and surname:='b' and etc.
But you risk deleting possible duplicates of people with the same name and age in the same city (this could happen).

But why don't you have access to the ID?
You should always include it.
You could hide it from grids but it should be there.
Title: Re: SQLite delete a record with no visible ID
Post by: af0815 on September 25, 2022, 05:51:36 pm
Not to have the PK is a design fault.
Title: Re: SQLite delete a record with no visible ID
Post by: Pe3s on September 25, 2022, 06:06:46 pm
there is an id in the project, but I don't want to see it in the table
Title: Re: SQLite delete a record with no visible ID
Post by: Thaddy on September 25, 2022, 06:08:25 pm
Not to have the PK is a design fault.
And a big one.
Title: Re: SQLite delete a record with no visible ID
Post by: rvk on September 25, 2022, 06:09:15 pm
there is an id in the project, but I don't want to see it in the table
I already said you could hide it in the tdbgrid.
But it should be in the sql.
Title: Re: SQLite delete a record with no visible ID
Post by: Pe3s on September 25, 2022, 06:34:16 pm
Thank you  :)
Title: Re: [SOLVED] SQLite delete a record with no visible ID
Post by: Zvoni on September 26, 2022, 08:56:54 am
And since it's SQLite it doesn't even matter if you have an explicit Primarykey (though i do agree that leaving out an explicit PK is a big design-fault).
As long as your table is not created with the option "WITHOUT ROWID" you'll always have a "hidden" primary Key
https://sqlite.org/rowidtable.html
TinyPortal © 2005-2018