GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Oct-2006, 05:43
shams shams is offline
New Member
 
Join Date: Dec 2004
Posts: 12
shams is on a distinguished road
Exclamation

how to prevent duplicate entries in mysql?


hi,
there is mysql table patients with id auto_increment, name and faher/name, how i can prevent duplicate entries for the same patient with name and fahter/name? thanks i dvanced for your help.
__________________
http://www.shams.at.tt
  #2  
Old 20-Oct-2006, 05:50
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 754
admin will become famous soon enough

Re: how to prevent duplicate entries in mysql?


Something like this perhaps? By creating a UNIQUE index on both columns, first_name and fathers_name?

Code:
CREATE TABLE `patient` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `first_name` VARCHAR( 100 ) NOT NULL, `fathers_name` VARCHAR( 100 ) NOT NULL, PRIMARY KEY ( `id` ), UNIQUE ( `fathers_name`, `first_name` ) );
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #3  
Old 20-Oct-2006, 18:47
shams shams is offline
New Member
 
Join Date: Dec 2004
Posts: 12
shams is on a distinguished road

Re: how to prevent duplicate entries in mysql?


there will be some patients that will have the same names and some of them will have the same father names the script should not prevent the same names or fahter names but the on they have exactly the same name and father name.
__________________
http://www.shams.at.tt
  #4  
Old 20-Oct-2006, 18:54
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 958
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: how to prevent duplicate entries in mysql?


how about giving a small example of the data you expect to see...

...and maybe a small example piece of the table data?
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #5  
Old 20-Oct-2006, 20:21
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 754
admin will become famous soon enough

Re: how to prevent duplicate entries in mysql?


If you created the DB table like I suggested, you can insert rows of patients like this:

Code:
id | first_name | fathers_name ----+-------------+--------------- 1 | Shaukat | Aziz 2 | Zulfiqar | Ali 3 | Liaquat | Ali 4 | Zeshan | Ali 5 | Zeshan | Rehman

AS you can see, you can have many patients with Ali as thier father's name. And many, with Zeshan as their first name.

Of course, you may not insert another Zeshan Ali for example. But in reality, it is entirely possible for 2 people to have the same first name and last (father's) name.

A much better way to structure this database table, is to use a unique identifier such as one supplied by the government i.e. an identification card, national registration card or passport number.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL in cygwin Avalon12 C++ Forum 0 01-Oct-2006 09:22
Cpanel downgrade MYSQL 4.1.X to MySQL 4.0.xx Webhosting-live Web Hosting Forum 1 01-Sep-2006 02:54
CPanel 10, Unlimited Emails, Unlimited Subdomains, Unlimited MySQL. $2.00 per Month Kalypsoweb Web Hosting Advertisements & Offers 0 30-Oct-2005 01:51
Windows: From only £20p/y,Linux: from $10p/m. ASP, ASP.NET, PHP, Free MySQL, +More EyotaHosts Web Hosting Advertisements & Offers 0 28-Jun-2003 13:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:08.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.