473,779 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unique Number for each row


I would like assign a number to each row in the table. The number can
be row number. For example, the first record in the table can be number
1.

I can do this thru VBA code. Can I do this via SQL ? If so, how?

...

Aug 14 '06 #1
4 2388
Set the field's type as autonumber at the table level...

Aug 14 '06 #2
<pi********@hot mail.comwrote
Set the field's type as autonumber at the table level...
However, do not expect this to be the equivalent of "Row Number" as that
term is used in some other databases. Autonumbers are for internal use,
especially as surrogate keys, and to be referenced by the foreign key fields
in related tables.

But, by definition, Records in relational DB Tables are _unordered_ and
ordering must be done when the data is retrieved via a Query or SQL
statement.

Larry Linson
Microsoft Access MVP
Aug 15 '06 #3

Thanks for the reply.

Now is it possible to do this with an update query?

pi********@hotm ail.com wrote:
Set the field's type as autonumber at the table level...
Aug 15 '06 #4
"Larry Linson" <bo*****@localh ost.notwrote in
news:xO8Eg.5564 5$zc2.25436@trn ddc06:
><pi********@ho tmail.comwrote
Set the field's type as autonumber at the table level...

However, do not expect this to be the equivalent of "Row Number"
as that term is used in some other databases. Autonumbers are for
internal use, especially as surrogate keys, and to be referenced
by the foreign key fields in related tables.
It's important to be sure you do *not* think of AutoNumbers as
either identity fields or as record numbers. An AutoNumber is really
just a special kind of default value. Most fields have a default
value field. You could set a date type field to a default value of
Date() so that today's date would be inserted when the record is
created. An AutoNumber is a similar type of default value, but an
incremented AutoNumber is a default vaulue of Max()+1 (it can also
be set to random, which picks a number from the entire range of
possible values storable in a long integer field).
But, by definition, Records in relational DB Tables are
_unordered_ and ordering must be done when the data is retrieved
via a Query or SQL statement.
This is something that people who've never actually studied the
theory behind SQL don't get. Data can have an ordering in the
physical storage, but SQL manipulates that data at a level that
ignores the physical ordering entirely -- all SQL resultsets must be
assumed to be unordered until you've placed an ORDER BY clause on
them. What that means is you can't count on a SQL statement with no
ORDER BY clause returning the data in the same order every time.

Secondly, record numbers make sense *only* when you're always
retrieving or navigating the entire table. In a networked
environment, that's very inefficient, so you'd be retrieving single
records or subsets of records. What good would an absolute record
number in the whole table do you when you're retrieving only one
record or a dozen?

In general, those who demand record numbers are trying to make
Access and SQL work the way the tools they've used in the past
worked (usually xBase-derived programming practices). They need to
get away from those assumptions ASAP.

Also, those who are asking for record numbers are often trying to
process data sequentially, when SQL UPDATES, which operate on sets,
would be much more efficient.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Aug 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2398
by: Tony Clarke | last post by:
Hi, I'm trying to write a system thats used for about 50 clients that uses html forms and php to log details. The problem is that when a client loads the form page it's given a value which is the last record in a table +1 (i.e. so its the next record). The problem with that is that a client could sit on that page for 20 mins (or whatever length of time) and a different client could use that record number and there what be an error...
8
4484
by: Joe Wong | last post by:
Hi, I need to implement a unique number generator that 1 or more processes on same or different machines will make use of it. Is there any library / project available already for this? Thanks in advance, -- Wong
4
10764
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group consisting of 6 numbers - with a total of 50 groups of numbers. A well-known girl that some publishing companies use to provide introductory level textbooks to various Junior Colleges in the U.S., not surprisngly, asks for this same exact...
2
7827
by: SJM | last post by:
I have a report that displays records of real estate properties. It is possible for each property to appear a number of times for various reasons. Each record however is unique. What I would like to do is display the total of the number of unique properties in the report footer, not just a count of the number of records. I have experimented with grouping on the property field and using running sums but to no avail. I have also tried to...
2
6560
by: D. Dante Lorenso | last post by:
I'm trying to build a table that will store a history of records by enumerating the records. I want the newest record to always be number ZERO, so I created a trigger on my table to handle the assignment of version numbers: CREATE TRIGGER "trg_audio_file_insert" BEFORE INSERT ON "public"."audio_file" FOR EACH ROW EXECUTE PROCEDURE "public"."trg_audio_file_insert"(); My trigger function looks like this...
2
4033
by: pstachy | last post by:
Hi again! I have another issue. I would like the attribute of the tag <invoice> to be unique. Made the following schema but unfortunately it doesn't validate. Could someone please indicate what is wrong or give me other solution. Thanks Very much. Regards ------------------------------------------------------------------------------------------------------------------ Schema:
9
18142
by: Robert Mago | last post by:
Is there a way to create a 10 characthers or less, alph-numeric string which is unique. I can't use the guid since its longer then 10 characthers. Also i cannot use a random number, since being random does not mean that its unique.
8
7209
by: Marc | last post by:
Hi all, I have to generate and send to a printer many 6 digit alphanumeric strings. they have to be unique but I cannot check in a database or something like that if it have already been printed. the string has also to seem a random one and it cannot have an apparence of a sequence. My first approach is to do it with a decimal counter and find and use an encryption alghorithm that converts each 6 digit decimal number to a 6 digit...
2
4448
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for statistical purposes. I've been using Here's the situation: I have two main tables:
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.