Recent

Author Topic: [SOLVED] SQLite delete a record with no visible ID  (Read 475 times)

Pe3s

  • Sr. Member
  • ****
  • Posts: 311
[SOLVED] SQLite delete a record with no visible ID
« 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?
« Last Edit: September 25, 2022, 06:34:34 pm by Pe3s »

rvk

  • Hero Member
  • *****
  • Posts: 5017
Re: SQLite delete a record with no visible ID
« Reply #1 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.
« Last Edit: September 25, 2022, 05:35:54 pm by rvk »

af0815

  • Hero Member
  • *****
  • Posts: 1036
Re: SQLite delete a record with no visible ID
« Reply #2 on: September 25, 2022, 05:51:36 pm »
Not to have the PK is a design fault.
regards
Andreas

Pe3s

  • Sr. Member
  • ****
  • Posts: 311
Re: SQLite delete a record with no visible ID
« Reply #3 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

Thaddy

  • Hero Member
  • *****
  • Posts: 12207
Re: SQLite delete a record with no visible ID
« Reply #4 on: September 25, 2022, 06:08:25 pm »
Not to have the PK is a design fault.
And a big one.
Manuals, manuals, manuals first.
You have incompetence and sheer incompetence.

rvk

  • Hero Member
  • *****
  • Posts: 5017
Re: SQLite delete a record with no visible ID
« Reply #5 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.

Pe3s

  • Sr. Member
  • ****
  • Posts: 311
Re: SQLite delete a record with no visible ID
« Reply #6 on: September 25, 2022, 06:34:16 pm »
Thank you  :)

Zvoni

  • Hero Member
  • *****
  • Posts: 1527
Re: [SOLVED] SQLite delete a record with no visible ID
« Reply #7 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
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018