AlphaPress Publishing
P.O. Box 5942 Albany, NY 12205
Tel: 518-250-3890
Email: alphapress@hotmail.com  


  
Click to buy this book from Amazon

Section Menu 

News

Pindaro is now working on a comprehensive book on SQL Server 2014.  For any comments you can email the author at alphapress@hotmail.com.

  

 

 

Create multi-field indexes to avoid duplicate records

To contact the author click here

This article is from the book "Access 2007 Pure SQL

To download the sample database click here


Discussion:

When working with customers you would like to make sure that no duplicate customer records exist in your database.  At the same time, it is logical that many customers might have the same last name and many of them the same first name.

Consequently, from a design point of view, we need to allow multiple customers to have the same last name or the same first name but not the same combination of both. We can easily solve this problem with a multi-field index. 

With a multi-field unique index, your database will accept values such as Smith John and Smith Tracy.  However, if you try to enter another Smith John in the database, then you will get a message that such entry violates existing index rules and will not be accepted.  Multi-field indexes are extremely useful to keep your data in a good state.  
 

Code:

CREATE UNIQUE INDEX indLastFirst ON tblCustomer1 (LastName, FirstName);
 

Result: