Add autonumber

J

Jeff

Hi,

I have a select query. There are 10 columns of data - I want to create
another column that is a primary key

How do you do this?

Thanks for your help.
 
B

BruceM

A query doesn't have a primary key, although you can add a primary key field
from a table, or from several tables. What would you like to accomplish by
adding the field (column)?
 
J

Jeff

I want to add a primary key to the table I create/or query, because I want to
be able to identify the fields uniquely - which is what a primary key should
do.

Are you kidding me - access cant add a primary key in a query - that is
pathetic.

How about adding a field that increases by 1 each row. So
NewColumn = 1,2,3,....

Is that doable?

Thanks for your input.
 
B

BruceM

No, I am not kidding, and I don't see it as even remotely pathetic. Select
queries are for arranging data that are stored in tables, and for performing
calculations of various sorts with the stored data. Other types of queries
can add and change data stored in tables, but you specifically mentioned a
select query.

You can add a PK field to the table. Just add the field. My quick test
shows that it populates as it should.

To increment by 1 with no gaps you could set the Default Value of a control
bound to a field to:
=DMax("YourField","YourTable")+1
For more information about this method, including its use in a multi-user
environment, see:
http://www.rogersaccesslibrary.com/download3.asp?SampleName=AutonumberProblem.mdb

To add sequential numbers to a query you could probably use or adapt
something like the following:
http://www.lebans.com/rownumber.htm

Remember that a PK can be used to uniquely identify a record, but that a PK
alone does not guarantee that the rest of the record is unique. A primary
key would not prevent your adding the same vendor twice to a Vendor table.
For that you would need a unique index on the Vendor name field, or on a
combination of Name and Address, or whatever is needed. Without that you
could have XYZ Corporation at 123 Main ST any number of times.
 
D

Dennis

So let me get this stright - you ask your question improperly, and when you
get an answer to your question AS ASKED, you get all pissy? I guess you get
the Jackass Award for this week....
 
Top