1 (edited by v_pozidis 2023-02-28 20:20:14)

Topic: avoid duplicate record

I have lost all my notes and I need your help.
I like to avoid the same record when pressing the save Button.
Avoid when the barcode and the Artist and the album and the date and the format exist, else it should save it.
thank you in advance

Post's attachments

Attachment icon test1.zip 325.43 kb, 92 downloads since 2023-02-28 

Re: avoid duplicate record

Hi,
I think lots of us do duplicate checks in different ways and I don't know that one is better than the other.
Attached is one option.
Derek.

Post's attachments

Attachment icon test1 option.zip 337.63 kb, 128 downloads since 2023-02-28 

Re: avoid duplicate record

Thank you derek

Re: avoid duplicate record

Hi V_pozidis, hi Derek

Here you can also advise to remove spaces (to the left and right of the text in the field) before any recording
and checking, otherwise misunderstandings are possible.

Re: avoid duplicate record

Hi Both,
Sparrow is absolutely right - I should have been removing all spaces at the start, at the end and in the middle of data just in case of typing errors.
Please see attached with the update (uses 'replacestr).
Derek.

Post's attachments

Attachment icon test1a option.zip 337.86 kb, 125 downloads since 2023-03-01 

6 (edited by v_pozidis 2023-03-01 18:19:15)

Re: avoid duplicate record

It wotlrks fine.
I found a topic from the past asking Dmitry the same and he gave me a answere in the following topic http://myvisualdatabase.com/forum/viewtopic.php?id=588 but when I insert it in my example for a reason it dosent work right. Can someone give me a solution . Unfortunately I have a black out and can not send you example. Please try it with my example test.zip. thank you.

Re: avoid duplicate record

Checking each field separately for the program in this form is incorrect and Derek's solution is optimal.
You were shown only an example and not a ready-made solution.
And Derek's example might need to be corrected for a normal database where there might be a separate
main table, singer table, format table, style table...
And this decision may already be different.

8 (edited by identity 2024-03-06 08:57:59)

Re: avoid duplicate record

Hi Derek
I was looking for duplicate script and came across your sample " test1a option.zip "
Its exactly what I needed for my project but with a slight modification.
What I need is that the messagebox ('Duplicate Record Found) is shown but let me choose to insert a duplicate record or not
In my project sometimes I need to add duplicate records .
Please tell me how to do this
thanks

Post's attachments

Attachment icon test1a option.zip 337.86 kb, 17 downloads since 2024-03-06 

Re: avoid duplicate record

Duplicate records is against the main purpose of a database, you should not have duplicated data in a database, use relationships.

Re: avoid duplicate record

tcoton wrote:

Duplicate records is against the main purpose of a database, you should not have duplicated data in a database, use relationships.


Don't confuse people.
Data in records may be repeated. For example, yesterday two identical shipments of goods were shipped to the same recipient. Two identical actions. Real case? So, in order for the same data to be present in the database, there is a unique primary key column, which guarantees that the records will be different. But the data may be repeated.
In this case, Identity asks how to check the data and, in case of a match, allow/disable recording using a question.

procedure frmCreate_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
  frmcreate.edit6.text := replacestr(uppercase(frmcreate.edit1.text + frmcreate.edit2.text + frmcreate.edit3.text + frmcreate.edit4.text + frmcreate.edit5.text),' ','');
  if sqlexecute('select count(*) from dedomena where duplicatecheck = "'+frmcreate.edit6.text+'"') > 0 then
    begin
     if (MessageBox('Dupplicate records. Continue save ?','WARNING !!!',MB_YESNO + MB_ICONWARNING + MB_DEFBUTTON2) = IDNO)
      and (frmcreate.edit6.text <> frmcreate.edit7.text) then cancel := true;
    end;
end;