Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Best way to have multiple Other category

Author  Topic 

iancuct
Yak Posting Veteran

73 Posts

Posted - 2003-02-06 : 12:06:16
I want to make a table of categories
fore example

Table Category

ID Name Property
1 Name1 10
2 Name2 20
3 Name3 30
4 Other 40

Where Other can be multiple things. For example one can specify other as a property of 40
or as a property of 55


its kind of weird

ID Name Property1 Property2
4 Other 40 $100
4 Other 55 $100

where the key is the ID or the name one or the other

what is better?
1 to make a new table for other
2 to make a list of categories names as a lookup table to the list of categories with the additional properties?

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-02-06 : 12:09:01
Use a normalized design. If the cardinality of category to property is 0:M, follow the rules of normalization to put property in a seperate table.

Jay White
{0}
Go to Top of Page

iancuct
Yak Posting Veteran

73 Posts

Posted - 2003-02-06 : 12:40:43
well the question is normalize it or just add a new field to the existing table

Go to Top of Page

iancuct
Yak Posting Veteran

73 Posts

Posted - 2003-02-06 : 14:17:44
well the question is normalize it or just add a new field to the existing table

Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-02-06 : 14:52:11
Adding fields is bad, M'kay?

Normalization is the way to go.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-02-06 : 15:41:05
Do you have a real life example?

What is Other? Does Other relate to the rest of the rows in the table?

Check out this site. It discusses DB Normalization.

http://www.sqlmag.com/Articles/Index.cfm?ArticleID=4887&pg=1

Go to Top of Page

iancuct
Yak Posting Veteran

73 Posts

Posted - 2003-02-06 : 15:42:49
i understand or maybe i don't
but lets say you have a simple list of fruits

apples
oranges
prunes
..
.
.
other


one of the fruits is other. but the fact is that other can be pears
or it can be bananas.

Now i can put otherID linked to otherTable
or i can make the key longer so that i can have multiple others, but i can't use one of the existing properties because they have to be different for each fruit (lets say) , so i have to add another property or another name to make the key longer.

what i don't know is which way should i do it

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-02-06 : 15:53:44
OK, Lets say you have a table that tracks the fruit you sell:

CREATE TABLE Fruit_Trans (Trans_Id Int, Quantity Int, Fruit_Id Int)

The reason you use an RDBMS is protect the integrity of you data. The Fruit_Trans table would then have a Parent. The Fruit_Code Table.

It might Look Like.

CREATE TABLE Fruity_Code (Fruit_Id Int, Fruit_Desc Varchar(255)

You would then establish Referential Integity between the two tables by making Fruit_Id in Fruit_Trans a foreign key to Fruit_Code. This will Prevent anyone entering a transaction about a fruit you know nothing about.

(You can also make Fruit Id a char/varchar and use the actual fruit name as your key. This prevents the need to join to the code table unless you need to get other information about the fruit, ie unit cost for example).

Now you say, but I have to enter a new fruit, and this can be handled procedurally. In your s/p that would insert a fruit transaction, check for the existance of the fruit in the code table, if it's not there, either return an output variable, or a return code that tells you top, lets say pop a fruit entry screen so that the new fruit can be entered.

OK...Now with all of THAT Said, there still is know way to prevent you from putting 'OTHER' or some other bogus data in the code table (well except with a validation rule of course).

Hope this diatribe helps.

Good Luck

Brett

8-)



Go to Top of Page

iancuct
Yak Posting Veteran

73 Posts

Posted - 2003-02-06 : 17:47:44
ok thanks, well i got it figured out.
I had to change an old table that had the category names as a key
to the same table but with an ID this way it
will allow for more multiple others

for example

FruitID Fruit Name
1 other
2 other

The requirements that i initially had were unclear and so i thought i had to have multiple other categories based on the name as a key.



Go to Top of Page
   

- Advertisement -