Results 1 to 3 of 3

Thread: QSqlQuery: How to check for duplicates before inserting record

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jan 2011
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanked 3 Times in 3 Posts

    Default Re: QSqlQuery: How to check for duplicates before inserting record

    Hi,

    even when selecting for the record prior to inserting it, you can not be sure that it still does not exist when you do the actual insert operation (unless you lock the whole table in advance). Instead, check your data model, decide which columns make up the uniqueness of the record and then create a unique index on the table with these columns. Then, when inserting the record, the database returns an error indicating a violation of the unique index if the record already exists.

    HTH,

    Andreas

  2. The following user says thank you to littletux for this useful post:

    homerun4711 (25th January 2011)

Similar Threads

  1. Replies: 7
    Last Post: 27th November 2010, 15:55
  2. Replies: 4
    Last Post: 23rd October 2010, 17:54
  3. Replies: 1
    Last Post: 2nd October 2010, 22:11
  4. Replies: 3
    Last Post: 26th March 2010, 04:32
  5. Inserting Record
    By Nefastious in forum Newbie
    Replies: 3
    Last Post: 20th October 2009, 04:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.