473,804 Members | 2,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How does a primary key become a negative number?

Ron
Hi all

I'm deciding whether to use the PK also as an account number, invoice
number, transaction number, etc that the user will see for the respective
files. I understand that sometimes a number will be missing, which is not a
problem for my purposes I don't think, but how would it be negative? Can
randomly created PK autonumber fields be negative? Any way for a PK,
autonumbered, *incremented* to be negative?

TIA
ron
Nov 13 '05
13 6544
"Ron" <ro************ *******@earthli nk.com> wrote in message news:<I5******* ***********@new sread1.news.pas .earthlink.net> ...
Hi all

I'm deciding whether to use the PK also as an account number, invoice
number, transaction number, etc that the user will see for the respective
files. I understand that sometimes a number will be missing, which is not a
problem for my purposes I don't think, but how would it be negative? Can
randomly created PK autonumber fields be negative? Any way for a PK,
autonumbered, *incremented* to be negative?


You have no control over the Autonumber field. You can reset it by
clearing out the table and compressing the database. But negative?
No. However, it is not that hard to roll your own PK, which is what I
would do in your case.

Edward
--
The reading group's reading group:
http://www.bookgroup.org.uk
Nov 13 '05 #11
Ron wrote:
Well, now I'm even *more* confused.


Hi Ron,

What I'm telling you applies to use of a primary key. In the
application you have described, the basic structure should include a
table for invoice header information and a second table for invoice line
items. It sounds as if you are planning to join the two tables in
queries by use of the invoice table's primary key - good - which you
are planing to make the invoice number - bad.

So I assumed you are using the primary key as a menas to link tables.

It truly is a good rule of thumb to have the means by which you link
tables together to be absolutey meaningless. That way you and your
users can happily tinker away with whatever scheme you have for
information. There are some instances when a developer might be tempted
to use actul real information as a PK and the one that comes to my mind
that is often used is an account number or component(s) of an account
number for multi-part account number set ups. How often is an account
number ever going to change?

Well, even bean counters screw up and decide an account number has to
change from time to time. I run a maintenance system which is fed
account numbers from a larger financial system and the maintenance
system populates account fields in various tables with an actual account
number to avoid the pain of having to associate the extra account
table(s) via a "meaningles s" system number in putting together SQL
statements. It always seemd to me to be a reasonable step until 2 years
ago when our university bean counters decided a coule of account codes
had to change. It was a hideous exercise trying to worm through all the
tables in our maintenance app (it does a lot of stuff and there are a
couple of hundred Oracle tables rife with account number information)
and change all these.

Having a link via a meaningless system generated number for the account
PK and linking the account table would have meant the account number
would needed to have been changed once, and once only.

So yes, I would strongly recommend you come up with two numbers to
generate - an autonumber for a PK and an autonumber or some other means
of generating a sequence for the invoice number.
--
Tim
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #12
I have a table on the BE containing the next available sequence number for
PO, Invoice ect. Use a function of get the next value, increment and write
out the next number to the BE table. Always have the function verify the
number does not exit before returning. Otherwise users could still get
duplicate values. Also check that the number sequence does not restart.

"Ron" <ro************ *******@earthli nk.com> wrote in message
news:Zx******** *********@newsr ead3.news.pas.e arthlink.net...
Thanks Paul, that helped A LOT! Hadn't even gotten to the
"multi-user"thoughts yet, but yeah, there could be 2 to 3 users (max) trying to save to the same file at the same time.

Thinking about it, though, I'll have a detail subform on my invoice form.
As the details are stored into their table, I need that linking InvoiceID,
so I won't be able to wait till they leave the invoice form to assign the
InvoiceID.

Anything wrong with putting a file on the BE that a routine can access
sooner to pull a number off for the next number up (for whatever file is
being added to) and then store the number+1 figure back into that field for the next user? System can lock that file, do the math, store the new number and unlock the file all pretty quickly. Wouldn't that solve the number+1
problem and still allow for multiple users? (Just thinking out in the open, here)

Sorry for all the probably really basic questions.

TIA
ron

"Paul" <pz****@rogers. com> wrote in message
news:Z4******** ************@ro gers.com...
BE CAREFUL IF YOU CHOOSE TO USE me!invID=nz(dma x("invID","Invo ice"),0)+1.
If 2 users try to make an invoice at the same time, they will both get the same ref number because their record has not yet been saved. Its better

to
assign the number when you leave the record. This way it will look up the number, assign it, save it and exit all at once. You could use a
docmd.runcomman d accmdsaverecord if you want, but I have seen some issues with hard drive traffic that stops this command from occuring.

HTH
Paul

"Bas Cost Budde" <b.*********@he uvelqop.nl> wrote in message
news:cn******** **@news2.solcon .nl...
Ron wrote:
> Hi all
>
> I'm deciding whether to use the PK also as an account number, invoice
> number, transaction number, etc that the user will see for the

respective> files. I understand that sometimes a number will be missing, which is> not a
> problem for my purposes I don't think, but how would it be negative? Can> randomly created PK autonumber fields be negative? Any way for a PK,
> autonumbered, *incremented* to be negative?

With Jet sure it is possible. There is even a technical reason for this: the high order bit of the binary representation is interpreted as the
number being negative.

Autonumbers are known to make frantic jumps now and then. You cannot rely on them climbing steadily.

Using your own incremential number is not too difficult. You must confine all actions on such a table to routes via your code (either via function calls or through forms that do the calculation of the new number)

Suppose you have a table Invoice, PK=invID (long). Have this in the
BeforeInsert handler of a form based on this table:

me!invID=nz(dma x("invID","Invo ice"),0)+1

This will yield 1 if there is no record yet, and the next free number if there are records.
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea



Nov 13 '05 #13
The recommendation that PKs be kept hidden from users stems from the
need for a PK to be a static value for each row in each table. If you
have a separate public identifier from the PK, then you can change
those identifiers at any time as needs be. If you're using the PK as
the identifier, then it really can't be changed without a whole mess
of updates and other pain and suffering.

So the question to ask yourself is "Will an
account/invoice/transaction number ever need to be changed?" It all
comes down to this issue. If the answer is a no, then you're okay
using a PK (either AutoNumber or roll-your-own) as an identifier. If
it's a yes, then you need to hide the PK and create another user
visible identifier. If you're not certain, the safer way to go is to
assume yes. Therefore many people consider it a best practice to hide
all PKs and create their own user visible identifiers.

Hope that helps,

Carlos

"Ron" <ro************ *******@earthli nk.com> wrote in message news:<j%******* ************@ne wsread1.news.pa s.earthlink.net >...
Well, now I'm even *more* confused.

The first responder tells me the incremented autonumber field shouldn't be
used as a PK so gave me a nice routine to come up with my own PK. No prob.
However, you seem to be saying I shouldn't use the PK (I'd assume even the
one I come up with using this nice routine) as a user-visible account
number, invoice number, etc. So, then, I now need 2 numbers I come up with,
one to show the user and one to be the actual PK?

I feel like one of those lil' ducks at the arcade shooting gallery that
reverses directions with each direct hit. Boing, I'm going left, boing I'm
going right. Help! Somebody stop me!

ron

Nov 13 '05 #14

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

Similar topics

15
2356
by: Claudio Grondi | last post by:
Let's consider a test source code given at the very end of this posting. The question is if Python allows somehow access to the bytes of the representation of a long integer or integer in computers memory? Or does Python hide such implementation details that deep, that there is no way to get down to them? The test code below shows, that extracting bits from an integer value n is faster when using n&0x01 than when using n%2 and I...
13
1803
by: Ron | last post by:
Hi All, Okay, I've read previous suggestions about not showing the primary key to the user of forms. If a number is to be shown (let's say, customer number) it should be generated independently of the primary key (which is autonumbered and no dups). I think I've gotten that all accomplished. However, now how should I link files, or perform query's? Should these types of things be based on the customer number I generate or should I...
4
2318
by: Henry | last post by:
Does anybody have a real-world sample of buiding a treeview control using data from database tables? All the sample code I have found either builds the treeview manually or uses a file directory as the sample. I have trouble translating those samples to working with data coming from my database, so I am hoping that someone could show me a sample of code that builds a tree from say a dataset. Many controls you can bind to a datasource,...
15
35523
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
3
5686
by: Joachim Klassen | last post by:
Hi all, if I accidentally use a TAKEOVER command with BY FORCE clause while primary and standby are in peer state I'll end up with two primary's (at least with FP10 and Windows). Is this works as designed or a bug ? Manuals say that the standby will inform the primary about the takeover but will not wait for acknowledgement, so the primary knows about whats going on. In my eyes primary should either switch to standby or shutdown...
3
3471
by: leah | last post by:
I encountered problem when i tried to create a primary key in an existing table which does not have one yet. There are too many records in it and it's hard to find out which one is 'duplicated'. I'm not sure whether, if there is any duplicate records in the table. How can i solve this problem? Thanks leah
20
5834
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including negative numbers into a separate sequence and ignore the (now empty) args list returned by getopt, but it would seem this is such a common requirement that there would be an option to treat a negative value as an argument. Note that this is only a...
34
2827
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
1
7781
by: santoshsri | last post by:
Hi All, My C# web application calls a webservice to process a report. It sends XMLs as parameter and in response gets an XML node which stores Binay datatype bin.base64. It makes an instance of the proxy class of webservice and makes a synchronous call to webservice GetReport() op. Here is the code snippet - *************************************************************************************** wbFELIP.wsZProcessReport.ProcessReport...
0
9571
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
10561
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
10302
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
9132
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...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
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
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.