www.webdeveloper.com
Results 1 to 3 of 3

Thread: how can reduce duplication in database?

  1. #1
    Join Date
    May 2012
    Posts
    3

    how can reduce duplication in database?

    This time i really need suggestion tell me about how can i reduce duplication in database.

  2. #2
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    the best way is to add unique keys to your table. So, depending on what columns need to be unique is what you would put the key on examples:

    email, username -- This would require that the email and username be unique.
    - me@mysite.com, kitty is not the same as me@mysite.com, cat both are unique
    - me@mysite.com, kitty is not the same as my@site.com, kitty both of these are unique

    But, if we were to split these into two different unique keys

    email -- This would require that only the email be unique
    username -- This would require that only the username be unique

    Now each one individually needs to be unique, whereas the first example both the email and username needed to be unique. I hope that makes sense.

    now when we do our query....

    Code:
    insert ignore into members (email, username) values ('me@mysite.com', 'kitty');
    that will insert into the database UNLESS it isn't unique, then nothing will be inserted.

    Or we can do:

    Code:
    insert into members (email, username) values ('me@mysite.com', 'kitty') on duplicate key update member_count = member_count + 1;
    Usually you wouldn't have this on a members table, but to get the example across, if you have a duplicate key, you can update the duplicate row instead of doing an insert.
    My settings

    Browser :: FireFox 1.5
    Resolution :: 1152x864
    Connection :: Cable Modem 2Mbs

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,359
    Quote Originally Posted by chamadii View Post
    This time i really need suggestion tell me about how can i reduce duplication in database.
    We may need a better explanation of what you mean by "duplication", if the prior reply does not address your problem.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles