473,508 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I need a number that can never be duplicated.

This will be a customer number that is automatically assigned. I want
it to be fast (so that it doesn't have to be checked for existance in
sql server) and impossible to ever reoccure. Could it be
date/hour/minute/second all as one integer?
Thanks,
Trint

.Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
21 1306
Where will you store this number and the other customer info? Will you ever use that number for validation or inserting detail
records??

Why not just let MSSQL generate the ID when you insert the customer data into the database?

--
Al Reid

"It ain't what you don't know that gets you into trouble. It's what you know
for sure that just ain't so." --- Mark Twain

"Trint Smith" <tr********@hotmail.com> wrote in message news:ub**************@TK2MSFTNGP12.phx.gbl...
This will be a customer number that is automatically assigned. I want
it to be fast (so that it doesn't have to be checked for existance in
sql server) and impossible to ever reoccure. Could it be
date/hour/minute/second all as one integer?
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2
Cor
Hi Trint,

Why not, have a look for Now.ticks for that

And do not forget to substract the ticks first from the point you did start
with your system till 0001 (is of course a fixed value).

I hope that was where you where looking for?

Cor
This will be a customer number that is automatically assigned. I want
it to be fast (so that it doesn't have to be checked for existance in
sql server) and impossible to ever reoccure. Could it be
date/hour/minute/second all as one integer?

Nov 20 '05 #3
* Trint Smith <tr********@hotmail.com> scripsit:
This will be a customer number that is automatically assigned. I want
it to be fast (so that it doesn't have to be checked for existance in
sql server) and impossible to ever reoccure. Could it be
date/hour/minute/second all as one integer?


You can use a GUID ('System.Guid').

;-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Ok, I will try that.
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5
If this number is to be stored in a SQL database anyway, you should
definitely use SQL to generate it. You say, however, that this is to be a
customer number so for it to have any real significance, it would have to be
stored somewhere, at some point, or you wouldn't need it?!
If you plan on using the customer number again (same customer purchases more
than once etc.), you will still have to "look it up".
Another note, if you ever have to enter this number by keying it in (ie -
typing), it is far better (more accurate) to type in a smaller integer than
a lengthy one.

To answer your question, yes and no, you could certainly use the combination
of Time related elements as you suggest as a moment in time will not be
repeated, but that number cannot be stored as an integer as it is too long.
You can store it as a Long Integer however.

Example: 02/12/2004 8:10:53
20040212081053


"Trint Smith" <tr********@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
This will be a customer number that is automatically assigned. I want
it to be fast (so that it doesn't have to be checked for existance in
sql server) and impossible to ever reoccure. Could it be
date/hour/minute/second all as one integer?
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #6
Cor, I just tested now.ticks and that is nice...I know it will be
different every time...It's 18 digits long now, will that change? I
mean, in the next 100 years? How long will it stay 18 digits? The
reason I ask is because I need to know the size my sql server 2k column
size needs to be.
Thanks,
Trint

.Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #7
Trint,
As Herfried stated, use System.Guid!

As System.Guid is a number that can be automatically assigned, that is fast,
and impossible to ever reoccur. (at least it is highly improbably that it
will ever reoccur).

I understand that System.Guid uses date/hour/minute/second plus some other
values to calculate a distinct value.

Hope this helps
Jay

"Trint Smith" <tr********@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
This will be a customer number that is automatically assigned. I want
it to be fast (so that it doesn't have to be checked for existance in
sql server) and impossible to ever reoccure. Could it be
date/hour/minute/second all as one integer?
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #8
Trint,
Do you have central daylight time where you are? More importantly will your
software run where there is central daylight time?

Now.Ticks will overlap an hour at least once a year, allowing duplicate
numbers!

Also, if you ever need to adjust the clock as the time is simply wrong,
Now.Ticks will overlap.

Again, I would recommend System.Guid, you can use either SQL Server or the
System.Guid structure itself to create a new one.

Hope this helps
Jay

"Trint Smith" <tr********@hotmail.com> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
Cor, I just tested now.ticks and that is nice...I know it will be
different every time...It's 18 digits long now, will that change? I
mean, in the next 100 years? How long will it stay 18 digits? The
reason I ask is because I need to know the size my sql server 2k column
size needs to be.
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #9
I just have to ask... Why are you trying to generate a customer number external to MSSQL then worrying about the column size in the
database. Why not just insert the customer data and return the MSSQL IDENTITY? If you are concerned about the number of digits,
you can set the starting value.

I have done a lot of database work (MS ACCESS, MSSQL, ORACLE) and have never tried to generate a unique ID external to the database.
Just curious, what advantage do you see in doing that way?

--
Al Reid

"It ain't what you don't know that gets you into trouble. It's what you know
for sure that just ain't so." --- Mark Twain

"Trint Smith" <tr********@hotmail.com> wrote in message news:OU**************@TK2MSFTNGP11.phx.gbl...
Cor, I just tested now.ticks and that is nice...I know it will be
different every time...It's 18 digits long now, will that change? I
mean, in the next 100 years? How long will it stay 18 digits? The
reason I ask is because I need to know the size my sql server 2k column
size needs to be.
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #10
Cor
Hi Trint,

The value of this property is the number of 100-nanosecond intervals that
have elapsed since 12:00 A.M., January 1, 0001.
I do not know how many customers you expect, but I think that you can start
at 1-1-2004 or something the ticks between that date and 1-1-0001 is the
amount of ticks you can subtract always.

Than you can in my opinion divide the result for a properiate expection of
new customers.

Or do you get every 100-nanosecond a new customer?

:-)

Cor
Cor, I just tested now.ticks and that is nice...I know it will be
different every time...It's 18 digits long now, will that change? I
mean, in the next 100 years? How long will it stay 18 digits? The
reason I ask is because I need to know the size my sql server 2k column
size needs to be.
Thanks,
Trint

Nov 20 '05 #11
Personally, I would use a GUID... It's based on time and has about a 1 in 1
trillion chance of being duplicated.

And its fast...
"Trint Smith" <tr********@hotmail.com> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
Cor, I just tested now.ticks and that is nice...I know it will be
different every time...It's 18 digits long now, will that change? I
mean, in the next 100 years? How long will it stay 18 digits? The
reason I ask is because I need to know the size my sql server 2k column
size needs to be.
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #12
Cor
Hi Jay B,

I am not saying that this is the one I would, choise, on the other hand when
someone invent something like this, than I say always why not.

In Europe the daylight time change is always on a saterday on sunday between
02 and 03 o'clock (mostly we write in a 24 hour clock), that is 100 times
in a century, because only the turn back important.

I think that the change that there is a new customer on that time is really
very low (although it can happen).

I am talking for Europe of course I do not know if that time change in the
USA is on a daylight time in the middle of the week.

Cor
Trint,
Do you have central daylight time where you are? More importantly will your software run where there is central daylight time?

Now.Ticks will overlap an hour at least once a year, allowing duplicate
numbers!

Also, if you ever need to adjust the clock as the time is simply wrong,
Now.Ticks will overlap.

Again, I would recommend System.Guid, you can use either SQL Server or the
System.Guid structure itself to create a new one.

Nov 20 '05 #13

"
Or do you get every 100-nanosecond a new customer?

:-)

Woudln't that be really nice if it were true? If you even charged a cent
for whatever you sold, you still would be loaded...

Cor
Cor, I just tested now.ticks and that is nice...I know it will be
different every time...It's 18 digits long now, will that change? I
mean, in the next 100 years? How long will it stay 18 digits? The
reason I ask is because I need to know the size my sql server 2k column
size needs to be.
Thanks,
Trint


Nov 20 '05 #14
I don't know how to:
insert the customer data and return the MSSQL IDENTITY.
And if Now.Ticks will overlap, I will have to use Herfried K. Wagner's
suggestion of System.Guid.
Thanks,
Trint

.Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #15
Will you show me a code example of System.Guid that will go in a string?
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #16
* Trint Smith <tr********@hotmail.com> scripsit:
Cor, I just tested now.ticks and that is nice...I know it will be
different every time...It's 18 digits long now, will that change? I
mean, in the next 100 years? How long will it stay 18 digits? The
reason I ask is because I need to know the size my sql server 2k column
size needs to be.


Did you have a look at the documentation what the tick count is? It
will start to run every time the system is rebooted and it will restart
after some days because of an overflow.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #17
* Trint Smith <tr********@hotmail.com> scripsit:
Will you show me a code example of System.Guid that will go in a string?


\\\
Dim s As String = Guid.NewGuid().ToString()
///

'ToString' accepts a format parameter, so you can format the GUID the
way you want.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #18
Trint,
Have you tried:

Dim g As Guid = Guid.NewGuid()
Dim s As String = g.ToString()

Hope this helps
Jay

"Trint Smith" <tr********@hotmail.com> wrote in message
news:O6*************@tk2msftngp13.phx.gbl...
Will you show me a code example of System.Guid that will go in a string?
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #19
Errata:

Forget my previos message... I misread something.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #20
"Cor" <no*@non.com> schrieb

Or do you get every 100-nanosecond a new customer?

:-)


Only an addition: The unit is 100-nanoseconds but the resolution might be
1/100s only.

...which should be still enough customers. :)
--
Armin

Nov 20 '05 #21
If you want to go this route, here's how I have SQL Server generate a RowID for me..

1. Use a Stored Procedure to add the new row

2. Use a parameter in the sproc to return the identit
DECLARE @NewRowID int OUTPU

3. Immediately after the INSERT and error check (if applicable), set @NewRowID to the identit
SET @NewRowID = Scope_Identity(

4. In your vb code, set the direction of the parameter to Output..
prmNewRowID.Direction = ParameterDirection.Outpu

5. After executing the sproc, retrieve the value from SQLCommand.Parameter
RowIDVariable = CInt(SQLCommand.Parameters("@NewRowID").Value

I think this is the best way to let SQL Server sort out unique numbers for records. It's very common in multi-user applications for the user to execute a transaction and then receive a unique number back from the database in this fashion

I hope this helps, it seems it would be nicer to have Customer #12345 rather than Customer #{D579116A-EE83-4fb0-BB87-72AF7E509088}. :-

Best Regards
Mark Lauser - Crimson Softwar

Nov 20 '05 #22

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

Similar topics

3
2848
by: Mirek Rusin | last post by:
....what is the best way to force duplicated unique or primary key'ed row inserts not to raise errors? duplicated rows can be ignored or updated as well - it really doesn't matter. to be...
1
1575
by: Gomez | last post by:
I have set up two tables ****current and ****history. The history table contains all the fields which I want to track changes on. The current table contains just the most recent information from...
4
2894
by: MJ | last post by:
When I look in relationships I find a couple of tables have duplicated themselves and the titles has an underline and then a number 1 after them. Do you have any idea what would be causing this? ...
1
1482
by: anonieko | last post by:
> This is a common problem with some solution > > /*********************************************************************************** * * Problem: * Determine the Duplicated Records in a...
7
1470
by: themastertaylor | last post by:
Hi, I work for a construction company and part of my job is sourcing materials. currently we have a spreadsheet based system whereby each site has a worksheet in the workbook with the standard...
7
2276
by: elgiei | last post by:
Good morning at all, i have to implement a server,that every n-seconds (eg. 10sec) sends to other clients,which files and directory has been deleted or modified. i build a n-tree, for each...
6
1632
by: Ryan Liu | last post by:
Hi, If I have tens of thousands DataRow in a DataTable and allow the end user to pick any DataColumn(s) to check for duplicated lines, the data is so large, is there a better API, algorithm can...
3
2010
by: Knowledge | last post by:
Good day mates, I'm trying to build a database to keep track of information that will be stored when my client kicks off his brand new Taxi Cab business. Initially it will be a one person...
3
5521
by: IZZI | last post by:
This code is created to find all duplicates in a list of number by using a binary search tree implemented as an array. I want to add a function to count how many numbers in the list are duplicated...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7124
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...
0
7326
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,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
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...
1
5053
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...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
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 ...
1
766
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.