View Single Post
  #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,581
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.
Reply With Quote