473,379 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Weird Unique ID

Hi,

I'm making a simple application which will store different items (in a SQL
server 2000 - MSDE database).
Each item has a unique ID in this form:

[max 2 characters][max 5 characters] / [max 4 characters] / [max 1
character] / [max 1 character]

an example:
AZ12345/1234/1/A
or
A 5/1/1/G

My question is, what would be the best way to store this in the database. A
way that I wou

Have a column for each part of this ID? Or store the entire string in one
column?

Here are my thougts on both of these options:

Option A (column for each part)
GOOD:
- easy sorting. If I wanted to sort by column2 I would just add "ORDER BY
column2"

BAD:
- All columns put together form a unique id. But sometimes some columns can
be NULL. And I'm
not allowed to do that if I make all columns Primary Keys (so they will be
Foreign Keys in related tables)
- it's not very practical passing 5 strings in the application :(

Option B(entire string in one column)
GOOD
- only one string in the application
- only one column

BAD
- sorting. I have to use substrings for sorting.
- sorting: e.g. sometimes column2 will be only 2 characters long, sometimes
5. So again,
problems with substrings

These are just my ideas... Please advise me on this one

thanks,
saso
Dec 1 '05 #1
4 1550
Saso,

What I would do would depend on the foreign key issue. If the foreign
keys are going to be pointing to the fragments of the id in your table (and
not the complete id itself), then I would say break it up into separate
columns. You can always use a default of '' for the columns which you think
would be null (they don't have to be, unless there is a distinction between
null and ''). You would also make these columns char columns, and not
varchar.

Then, you can create a view on the table which would create a column
which has the complete id, should you need it. Either that, or a computed
column.

If your foreign key is going to depend on the complete, constructed key,
then I would definitely store that, and worry about parsing it later. You
could always create functions which will parse out the parts of the id you
want, and store those as columns. Then you can sort on those easily.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:dm**********@planja.arnes.si...
Hi,

I'm making a simple application which will store different items (in a SQL
server 2000 - MSDE database).
Each item has a unique ID in this form:

[max 2 characters][max 5 characters] / [max 4 characters] / [max 1
character] / [max 1 character]

an example:
AZ12345/1234/1/A
or
A 5/1/1/G

My question is, what would be the best way to store this in the database.
A way that I wou

Have a column for each part of this ID? Or store the entire string in one
column?

Here are my thougts on both of these options:

Option A (column for each part)
GOOD:
- easy sorting. If I wanted to sort by column2 I would just add "ORDER BY
column2"

BAD:
- All columns put together form a unique id. But sometimes some columns
can be NULL. And I'm
not allowed to do that if I make all columns Primary Keys (so they will
be Foreign Keys in related tables)
- it's not very practical passing 5 strings in the application :(

Option B(entire string in one column)
GOOD
- only one string in the application
- only one column

BAD
- sorting. I have to use substrings for sorting.
- sorting: e.g. sometimes column2 will be only 2 characters long,
sometimes 5. So again,
problems with substrings

These are just my ideas... Please advise me on this one

thanks,
saso

Dec 1 '05 #2
Thanks for your reply,

No... The foreign keys use the entire string as an ID. So I agree...
the second option (storing complete ID in 1 column) sounds better.

My question is... how to sort when IDs can be in very different forms:

A 1///Z
AZ12345/1234/1/1

(most problematic is the first part because it's made out of two parts:
max 2 chars + max 5 chars)

I can't use substring because it will throw an error when all characters
aren't filled.

How would you do this?

thanks,
saso

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eF**************@TK2MSFTNGP12.phx.gbl...
Saso,

What I would do would depend on the foreign key issue. If the foreign
keys are going to be pointing to the fragments of the id in your table
(and not the complete id itself), then I would say break it up into
separate columns. You can always use a default of '' for the columns
which you think would be null (they don't have to be, unless there is a
distinction between null and ''). You would also make these columns char
columns, and not varchar.

Then, you can create a view on the table which would create a column
which has the complete id, should you need it. Either that, or a computed
column.

If your foreign key is going to depend on the complete, constructed
key, then I would definitely store that, and worry about parsing it later.
You could always create functions which will parse out the parts of the id
you want, and store those as columns. Then you can sort on those easily.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:dm**********@planja.arnes.si...
Hi,

I'm making a simple application which will store different items (in a
SQL server 2000 - MSDE database).
Each item has a unique ID in this form:

[max 2 characters][max 5 characters] / [max 4 characters] / [max 1
character] / [max 1 character]

an example:
AZ12345/1234/1/A
or
A 5/1/1/G

My question is, what would be the best way to store this in the database.
A way that I wou

Have a column for each part of this ID? Or store the entire string in one
column?

Here are my thougts on both of these options:

Option A (column for each part)
GOOD:
- easy sorting. If I wanted to sort by column2 I would just add "ORDER BY
column2"

BAD:
- All columns put together form a unique id. But sometimes some columns
can be NULL. And I'm
not allowed to do that if I make all columns Primary Keys (so they will
be Foreign Keys in related tables)
- it's not very practical passing 5 strings in the application :(

Option B(entire string in one column)
GOOD
- only one string in the application
- only one column

BAD
- sorting. I have to use substrings for sorting.
- sorting: e.g. sometimes column2 will be only 2 characters long,
sometimes 5. So again,
problems with substrings

These are just my ideas... Please advise me on this one

thanks,
saso


Dec 2 '05 #3
what i have done in the past for the maximum number of rows and smallest key
length is below
1st byte 0=9, A-Z
2nd byte 6 numbers 00000000
1
0 000000
0 000001
0 000002
1st byte changes when 2 set of numbers reach
0 99999999 sets 1st byte to 1 and then start 2nd set over
1 000000
1 0000001

you end up with 36 * 999999=35,999,964
thats quite a lot of rows...in total of 7 Characters
you could also add or use 8 character date
yyyymmdd
20051230+ some number you will never reach in a 24 hour period
day changes and reset the number part too 0000's
the 2 above samples will even order correct desc or Asc

dave
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:dm**********@planja.arnes.si...
Hi,

I'm making a simple application which will store different items (in a SQL
server 2000 - MSDE database).
Each item has a unique ID in this form:

[max 2 characters][max 5 characters] / [max 4 characters] / [max 1
character] / [max 1 character]

an example:
AZ12345/1234/1/A
or
A 5/1/1/G

My question is, what would be the best way to store this in the database. A way that I wou

Have a column for each part of this ID? Or store the entire string in one
column?

Here are my thougts on both of these options:

Option A (column for each part)
GOOD:
- easy sorting. If I wanted to sort by column2 I would just add "ORDER BY
column2"

BAD:
- All columns put together form a unique id. But sometimes some columns can be NULL. And I'm
not allowed to do that if I make all columns Primary Keys (so they will be Foreign Keys in related tables)
- it's not very practical passing 5 strings in the application :(

Option B(entire string in one column)
GOOD
- only one string in the application
- only one column

BAD
- sorting. I have to use substrings for sorting.
- sorting: e.g. sometimes column2 will be only 2 characters long, sometimes 5. So again,
problems with substrings

These are just my ideas... Please advise me on this one

thanks,
saso

Dec 2 '05 #4
Thanks for your reply Dave,

However, I fail to see how this would help me in my example, since
I'm required to use the EXACT ID that I described earlier.

My question was how to sort when I have entries like this:

1///G
Z 1/1//G
ZZ12345/1234/1/1

and sometimes I have to sort by using the first column or second or third,
....

saso
"Dave" <dv*****@sbcglobal.net> wrote in message
news:9k******************@newssvr25.news.prodigy.n et...
what i have done in the past for the maximum number of rows and smallest key length is below
1st byte 0=9, A-Z
2nd byte 6 numbers 00000000
1
0 000000
0 000001
0 000002
1st byte changes when 2 set of numbers reach
0 99999999 sets 1st byte to 1 and then start 2nd set over
1 000000
1 0000001

you end up with 36 * 999999=35,999,964
thats quite a lot of rows...in total of 7 Characters
you could also add or use 8 character date
yyyymmdd
20051230+ some number you will never reach in a 24 hour period
day changes and reset the number part too 0000's
the 2 above samples will even order correct desc or Asc

dave
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:dm**********@planja.arnes.si...
Hi,

I'm making a simple application which will store different items (in a SQL server 2000 - MSDE database).
Each item has a unique ID in this form:

[max 2 characters][max 5 characters] / [max 4 characters] / [max 1
character] / [max 1 character]

an example:
AZ12345/1234/1/A
or
A 5/1/1/G

My question is, what would be the best way to store this in the database.
A
way that I wou

Have a column for each part of this ID? Or store the entire string in
one column?

Here are my thougts on both of these options:

Option A (column for each part)
GOOD:
- easy sorting. If I wanted to sort by column2 I would just add "ORDER BY column2"

BAD:
- All columns put together form a unique id. But sometimes some columns

can
be NULL. And I'm
not allowed to do that if I make all columns Primary Keys (so they

will be
Foreign Keys in related tables)
- it's not very practical passing 5 strings in the application :(

Option B(entire string in one column)
GOOD
- only one string in the application
- only one column

BAD
- sorting. I have to use substrings for sorting.
- sorting: e.g. sometimes column2 will be only 2 characters long,

sometimes
5. So again,
problems with substrings

These are just my ideas... Please advise me on this one

thanks,
saso


Dec 3 '05 #5

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

Similar topics

5
by: python newbie | last post by:
hey, okay, I'm trying to figure out why my books: Quick Python, Python in a Nutshell, Python Cookbook and Learning Python don't say anything about the weird behavior of a list when you have one as...
1
by: Bernard Drolet | last post by:
Hi, I have a recursive table containing complex SGML documents. The table has a primary key "objectref"; to determine what object is actually valid, I have the columns validtime and obsoletetime,...
1
by: David Wake | last post by:
I have two radio buttons and two checkboxes in a form. I'm trying to write some code so that when a radio button is selected, its corresponding checkbox is disabled. My code looks like this: ...
7
by: LRW | last post by:
Below I'll paste my CSS and the HTML in question. But what's happening is, I'm trying to establish a link behavior for a class that's separate from the normal link class. I've established a: 's...
82
by: nobody | last post by:
Howdy, Mike! mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0402271647.c20aea3@posting.google.com>... > I'm a C++ programmer, and have to use lisp because I want to use >...
4
by: Andromeda | last post by:
I have two tables... one contains all the loan officer information (name/address/phone/email/etc) the other is a NH license table which lists has 3 columns - txtLOName, dtDateHireSent,...
1
by: Pankaj | last post by:
Hi All, I use a Hashtable in my program to keep unique items...at one instance I need to repopulate this hashtable through a loop. when starting repopulation hashtable.count() returns ZERO...
1
by: Dean | last post by:
I've been using listboxes for a long time with no problems but I have a weird problem on a page that I can't figure out.... I'm filling a listbox, as usual with a dataset but when the user...
0
by: mvsguy | last post by:
I'm running a script from the PC Command Center to a z/OS DB2 at v8.1.5. In mid script, the schema changes, despite my setting it explicitly at the start of the script. Does anyone know what...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.