Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Primary Key in Microsoft Access

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi!

I was wondering if anyone of you guys knew how to create a custom primary key in access. Currently I am using an autonumber field as my primary key. I would like to have the autonumber field start at a higher value (e.g 1000). Also, is there any way to create a PrimaryKey that is alpha-numeric (e.g A100B39)?

I would greatly appreciate any help :)

Thanks!

Kimberly
 
Using auto-number as your promary key is maybe the safest way to ensure that the primary key field will have unique value;

In situations where you can't guarantee the uniqueness of any single field, you may be able to designate two or more fields as the primary key.
For example, an Order Details table can relate the Orders and Products tables. Its primary key consists of two fields: OrderID and ProductID. The Order Details table can list many products and many orders, but each product can only be listed once per order, so combining the OrderID and ProductID fields produces an appropriate primary key.

Combining two fields as primary key (one text, another autonumber field value), you can get desired alpha-numeric key
 
CF has a function called CreateUUID which returns a 35 digit hexidecimal number, and I use it to create a primary key. Not absolutly foolproof, but it works for me. Sylvano is right about using combimation keys. I have some of those, too. BTW, I usually do something like the following to create a primary key:
Code:
<cfset newid = #CreateUUID()#>

INSERT INTO Table
(PrimaryKey)
VALUES
('#newid#')

You could use the function directly in the insert, but I usually do it this way, so I can reference the entry I just created further down the page. Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top