473,385 Members | 1,888 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,385 software developers and data experts.

let me count the ways

hey all,
let's say i have some categories that i want to attach to a product. my
thought on storing this information was storing each of the categories for a
particular product into one database field, semicolon delimited?

is there a another way to do this? if the above option is desired what would
be the best way to separate the categories out when reading the product from
the database?

thanks,
rodchar
Aug 8 '07 #1
5 1063
On Aug 8, 3:34 pm, rodchar <rodc...@discussions.microsoft.comwrote:
hey all,
let's say i have some categories that i want to attach to a product. my
thought on storing this information was storing each of the categories for a
particular product into one database field, semicolon delimited?

is there a another way to do this? if the above option is desired what would
be the best way to separate the categories out when reading the product from
the database?

thanks,
rodchar
That approach wouldn't even satisfy the conditions for 1NF. Wouldn't
it better to create a category and add a foreign key reference to it
from the product table? That way you could easily separate them out
when quering. Do you have a specific reason for choosing a
denormalized structure?

Aug 8 '07 #2
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:C7**********************************@microsof t.com...
hey all,
let's say i have some categories that i want to attach to a product. my
thought on storing this information was storing each of the categories for
a
particular product into one database field, semicolon delimited?

is there a another way to do this? if the above option is desired what
would
be the best way to separate the categories out when reading the product
from
the database?
What you need here is a classic "many-to-many" relationship e.g.

Products
---------
ProductID int
Product varchar(50)

Categories
-----------
CategoryID int
Category varchar(50)

ProductCategories
-------------------
ProductID
CategoryID

This allows you to map the relationship between products and categories. One
product can be in many categories, and one category can contain many
products...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 8 '07 #3
On Aug 8, 3:53 pm, Brian Gideon <briangid...@yahoo.comwrote:
On Aug 8, 3:34 pm, rodchar <rodc...@discussions.microsoft.comwrote:
hey all,
let's say i have some categories that i want to attach to a product. my
thought on storing this information was storing each of the categories for a
particular product into one database field, semicolon delimited?
is there a another way to do this? if the above option is desired what would
be the best way to separate the categories out when reading the product from
the database?
thanks,
rodchar

That approach wouldn't even satisfy the conditions for 1NF. Wouldn't
it better to create a category and add a foreign key reference to it
from the product table? That way you could easily separate them out
when quering. Do you have a specific reason for choosing a
denormalized structure?
Err...you'd need to create a category table *and* a table that relates
products to categories in a many-to-many relationship.

Aug 8 '07 #4
GS
from using sql database search aspect, one single field for multiple
value(attributes) is bad
Suppose you want select product by categories, with delimited field holding
multiple categories the search would be brutally slow and expensive and
definitely not scalable.
you should have association table

productID category
and you can query the joint tables very easily and quickly with simple sql

select p.product , Category from Productstable as p, CategoryTable as c
where p.productID = c.productID and category ="somecategory"
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:C7**********************************@microsof t.com...
hey all,
let's say i have some categories that i want to attach to a product. my
thought on storing this information was storing each of the categories for
a
particular product into one database field, semicolon delimited?

is there a another way to do this? if the above option is desired what
would
be the best way to separate the categories out when reading the product
from
the database?

thanks,
rodchar

Aug 8 '07 #5
Thanks everyone for sharing this generous knowledge.
Rod.

"rodchar" wrote:
hey all,
let's say i have some categories that i want to attach to a product. my
thought on storing this information was storing each of the categories for a
particular product into one database field, semicolon delimited?

is there a another way to do this? if the above option is desired what would
be the best way to separate the categories out when reading the product from
the database?

thanks,
rodchar
Aug 10 '07 #6

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

Similar topics

4
by: leegold2 | last post by:
Below is some code from a FULLTEXT search. My question is how do I get a count of the number of rows found by the search? $query="SELECT * FROM balloon_txt WHERE MATCH(access_no, recs_txt)...
22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
5
by: cc | last post by:
From the popular website At this link: http://www.w3schools.com/asp/asp_globalasa.asp I got this code, but it does not work on my server... I can open three IE browsers and watch the count go to...
1
by: JohanS | last post by:
Hi count(v.begin(), v.end(), 5) is easy for a vector of int's. But how do i make it work with a class object? I have tried a few ways but can't get it to work since i don't really understand...
5
by: Cro | last post by:
Hello Access Developers, I'd like to know if it is possible to perform a count in an expression that defines a control source. My report is based on a query. In my report, I want a text box to...
3
by: amanda | last post by:
Hope someone can help me with this - I've been staring at it stupidly for hours now, convinced there must be an easy way to achieve the results I want: I have a very large table recording every...
5
by: Karl Irvin | last post by:
In VBA, how do you see the results of an sql count statement like the following ? Select Count (*) as Total from tblCustomer Result = DoCmd.RunSql("Select Count (*) as Total from...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
2
by: Pete | last post by:
I need to create a single query (Not a SQL query) against a single table that counts the number of records in the table, where the single field "tmp" contains specific string values If the field...
2
by: ems9tech | last post by:
I can't get this count to return a number without an empty quote at the end ( " ) or getting NaN. Does anyone know why? I've searched and don't see any other postings on this issue. I'm using VS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
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
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
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,...

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.