WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-21-2004, 12:26 PM
robertma robertma is offline
WebProWorld New Member
 

Join Date: Jul 2004
Posts: 1
robertma RepRank 0
Default Duplicate Search Query

Hi,

We have a 'Customer Details' form and on which we record basic details i.e. Name, Address, Tel number etc.

The problem we are experiencing is that customers are being contacted a number of times because users are too lazy to search the database and are creating new records every time contact is made with a customer, rather than search if any existing details are held. (Each time a new record is created a telephone call is made and letter sent).

Users have been warned countless times but we have been fruitless in success, what I have found for example is that if they are speaking to Mr Jones, they will search the name Jones find 213 records and create a new records rather than find the one applicable to him. (I know they could then again do a further search but this does not happen)

Ideally what I would like is that when a user clicks on the 'Create New Record' command button which takes them to a new record. A 'Pop Up' will appear with two field’s i.e. Customer name and postcode (These fields are ones used on the form).

The user can then enter these to quickly view any records that match the 2 fields.

Long winded I know but I’d be grateful for any help anyone can give, Please find attached the database used

Thanks

Matthew
Reply With Quote
  #2 (permalink)  
Old 07-21-2004, 04:44 PM
mushroom's Avatar
mushroom mushroom is offline
WebProWorld Veteran
 

Join Date: Feb 2004
Location: Queen Charlotte B. C. Canada
Posts: 351
mushroom RepRank 0
Default

If you where to create a primary key using "Customer name" & "Phone #" no duplicates are allowed.
__________________
Irony: That for most people the most "trusted" web site on the planet is for a company the has been convicted of criminal activity.

Both Security and SuSe start with "S". www.oldslides.com
Reply With Quote
  #3 (permalink)  
Old 07-21-2004, 04:46 PM
M0rtym0use M0rtym0use is offline
WebProWorld Member
 

Join Date: May 2004
Location: UK
Posts: 83
M0rtym0use RepRank 0
Default

robertma,
the best way to do this is before creating the record check to see if a record already exists. If is does then display an error message else create a new record.

the way you would implement would obviously depend on the db type eg mssql, access, mysql,oracle etc.
and the programming language you would use to implement this

MM
__________________
M0rtyM0use

Simply Rugby
Reply With Quote
  #4 (permalink)  
Old 07-21-2004, 11:58 PM
ronniethedodger's Avatar
ronniethedodger ronniethedodger is offline
WebProWorld 1,000+ Club
 

Join Date: Aug 2003
Location: Central US
Posts: 1,576
ronniethedodger RepRank 0
Default

That is what the Primary Key will do as Mushroom suggested. If you try to Insert the record, it will throw an error -- no need to check, the database engine does it for you.

In MySQL, you would get the following message:
Code:
Error: 1022 SQLSTATE: 23000 (ER_DUP_KEY) Message: Can't write; duplicate key in table '%s'
All you need to do is build proper error traps and then resolve the errors accordingly. For proper MySQL error handling, refer to http://dev.mysql.com/doc/mysql/en/Error-handling.html for more information.

This is also the preferred way of building database table structures. There will be cases that data could be loaded externally as from a text file. Letting the database engine do the checking for you and disallowing insertion of duplicate key values protects the integrity of the table.
__________________
Ronnie T. Dodger
Web Design Forum-Web Design & Development News
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Tags: duplicate, query, search



Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Search Engine Friendly URLs by vBSEO 3.0.0