473,785 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1578
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.co m

"Saso Zagoranski" <sa************ *@guest.arnes.s i> 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.c om> wrote in
message news:eF******** ******@TK2MSFTN GP12.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.co m

"Saso Zagoranski" <sa************ *@guest.arnes.s i> 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,9 64
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.s i> 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*****@sbcglo bal.net> wrote in message
news:9k******** **********@news svr25.news.prod igy.net...
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,9 64
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.s i> 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
1457
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 an object instance member. for instance (my first pun of 2004), if I have, test.py ----------------
1
1940
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, which tell me when the object becomes, as you expect, valid and obsolete. I ran the following query, that is supposed to return me the structure from a specific node (identified with objectref = 7754087) up to the top parent. SELECT
1
6218
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: function radioClicked(index) { document.table_config_form.my_checkbox.disabled = true;
7
3403
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 with no underline and then an underline for hover...but oddly, only ONE link will actually show the underline on hover. All the rest, even with the same HTML, won't pop up an underline. I just don't get it! If I could get any advice I'd really...
82
5389
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 > emacs. I've gotten a book on lisp, and I must say lisp is the ugliest > looking language syntax wise. What is up with this: (defun(foo()). (DEFUN FOO () NIL) > What were the lisp authors thinking? Why did Stallman use lisp in
4
2087
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, dtDateTermSent and the tables are joined on the LO's name. I need to create two queries for this.. one for when I tell NH the LO is hired, and one for when I tell them they're fired. It's the hiring one I can't get straight. Basically, I need listed on...
1
1293
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 hence first item gets added successfully but as soon as the control reaches top of foreach loop somehow a second item which indeed existed before repoulation started appears in hashtable and count returns two hence this second item can not add...
1
880
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 selects some entries, other entries get returned instead of the one selected. Also, some items in the list don't trigger the SelectedIndexChanged event and this is repeatable - the same items always fail to generate an event. All of this seems to...
0
1719
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 might cause this? Here's a snip from the script output - SELECT CURRENT SQLID, CURRENT SCHEMA FROM SYSIBM.SYSDUMMY1 --------
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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
10325
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
10091
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
8972
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
6739
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();...
1
4050
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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.