dbTalk Databases Forums  

how to design tables to store random number of columns

comp.databases comp.databases


Discuss how to design tables to store random number of columns in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
derek.gtalk@gmail.com
 
Posts: n/a

Default how to design tables to store random number of columns - 09-11-2006 , 05:22 AM






Hi,

I want to design a generic solution to store different data sources.
One data source may have 10 columns, while the other may have 100+. I
know a few solutions, but none of them seems ideal. Could you give me
some advice? My solutions are listed below:

1. one record only holds one column. so the table will look like:

data_Id, columnId, dataValue

This table may have millions of records easily.

2. put all the columns into one record as below:
data_Id, column_1, column_2, ..., column_N

Obviously we don't know the N in advance. When we got another data
source which has more columns, have to append more columns to the
existing table. The other drawback is that it wastes lots of space for
other data sources whose number of columns is less than N.

3. the solution combines the above two.
data_Id, segment_Id, column_1, column_2, ..., column_M

For a data source which has N columns, it will have N/M records for
each message data.

Regards,
Derek


Reply With Quote
  #2  
Old   
Michael Zedeler
 
Posts: n/a

Default Re: how to design tables to store random number of columns - 09-11-2006 , 05:39 AM






derek.gtalk (AT) gmail (DOT) com wrote:
Quote:
I want to design a generic solution to store different data sources.
One data source may have 10 columns, while the other may have 100+. I
know a few solutions, but none of them seems ideal. Could you give me
some advice? My solutions are listed below:
It all depends on what you ae going to do with the data. I am sure
you'll get more useful advice if you outline what the purpose is.

Regards,

Michael.
--
Which is more dangerous? TV guided missiles or TV guided families?
I am less likely to answer usenet postings by anonymous authors.
Visit my home page at http://michael.zedeler.dk/


Reply With Quote
  #3  
Old   
derek
 
Posts: n/a

Default Re: how to design tables to store random number of columns - 09-11-2006 , 06:08 AM



at the first stage, what I need is to design a table or tables to store
different data sources efficiently. I may need to query or do some
statistic on those data later on.


Reply With Quote
  #4  
Old   
Michael Zedeler
 
Posts: n/a

Default Re: how to design tables to store random number of columns - 09-11-2006 , 08:02 AM



derek wrote:
Quote:
at the first stage, what I need is to design a table or tables to store
different data sources efficiently. I may need to query or do some
statistic on those data later on.
This answer doesn't add any information that I didn't already have,
except that it seems to be for read only access. Also, you write "store
data sources". In my terminology there is a difference between a data
source and data. The data source is basically just a reference to the
database (my-database-server.mydomain.com with login credentials).

Regards,

Michael.
--
Which is more dangerous? TV guided missiles or TV guided families?
I am less likely to answer usenet postings by anonymous authors.
Visit my home page at http://michael.zedeler.dk/


Reply With Quote
  #5  
Old   
derek
 
Posts: n/a

Default Re: how to design tables to store random number of columns - 09-11-2006 , 08:47 AM



sorry, i mean to store data from different external systems.


Reply With Quote
  #6  
Old   
Ed Prochak
 
Posts: n/a

Default Re: how to design tables to store random number of columns - 09-11-2006 , 03:54 PM




derek.gtalk (AT) gmail (DOT) com wrote:
Quote:
Hi,

I want to design a generic solution to store different data sources.
One data source may have 10 columns, while the other may have 100+. I
know a few solutions, but none of them seems ideal. Could you give me
some advice? My solutions are listed below:

1. one record only holds one column. so the table will look like:

data_Id, columnId, dataValue

This table may have millions of records easily.

2. put all the columns into one record as below:
data_Id, column_1, column_2, ..., column_N

Obviously we don't know the N in advance. When we got another data
source which has more columns, have to append more columns to the
existing table. The other drawback is that it wastes lots of space for
other data sources whose number of columns is less than N.

3. the solution combines the above two.
data_Id, segment_Id, column_1, column_2, ..., column_M

For a data source which has N columns, it will have N/M records for
each message data.

Regards,
Derek
you are trying to recreate a DBMS. Create tables specific for each
source. If you really cannot do that, use the filesystem. Creating
tables on-the-fly is a really bad idea. Unmaintainable, unnormalized,
just a disaster waiting to happen.

Ed



Reply With Quote
  #7  
Old   
Jerry Gitomer
 
Posts: n/a

Default Re: how to design tables to store random number of columns - 09-11-2006 , 08:28 PM



derek.gtalk (AT) gmail (DOT) com wrote:
Quote:
Hi,

I want to design a generic solution to store different data sources.
One data source may have 10 columns, while the other may have 100+. I
know a few solutions, but none of them seems ideal. Could you give me
some advice? My solutions are listed below:

1. one record only holds one column. so the table will look like:

data_Id, columnId, dataValue

This table may have millions of records easily.

2. put all the columns into one record as below:
data_Id, column_1, column_2, ..., column_N

Obviously we don't know the N in advance. When we got another data
source which has more columns, have to append more columns to the
existing table. The other drawback is that it wastes lots of space for
other data sources whose number of columns is less than N.

3. the solution combines the above two.
data_Id, segment_Id, column_1, column_2, ..., column_M

For a data source which has N columns, it will have N/M records for
each message data.

Regards,
Derek

Only solution 1 will provide you with a normalized database and
avoid the need for system modifications in the event additional
data sources are required and/or existing data sources require
additional columns.

Multi-million row tables, if properly indexed, don't present
performance problems.

HTH
Jerry


Reply With Quote
  #8  
Old   
--CELKO--
 
Posts: n/a

Default Re: how to design tables to store random number of columns - 09-12-2006 , 11:43 AM



Quote:
I want to design a generic solution to store different data sources. One data source may have 10 columns, while the other may have 100+. I know a few solutions, but none of them seems ideal. Could you give me some advice?
This is not a table BY DEFINITION; you have to know all the attributes
that identify the entity you are modeling. You are not allowed a
"Briteney Spears, automobiles or squid" construct in RDBMS.

For something this vague and poorly defined, I would just use notes in
English until I was able to make a proper data model.

What are you actually trying to do?



Reply With Quote
  #9  
Old   
FreeData
 
Posts: n/a

Default Re: how to design tables to store random number of columns - 09-12-2006 , 04:39 PM



Quote:
Hi,

I want to design a generic solution to store different
data sources. One data source may have 10 columns, while
the other may have 100+. I know a few solutions, but none
of them seems ideal. Could you give me some advice? My
solutions are listed below:
1. one record only holds one column. so the table will
look like:
data_Id, columnId, dataValue

This table may have millions of records easily.

2. put all the columns into one record as below:
data_Id, column_1, column_2, ..., column_N

Obviously we don't know the N in advance. When we got
another data source which has more columns, have to append
more columns to the existing table. The other drawback is
that it wastes lots of space for other data sources whose
number of columns is less than N.
3. the solution combines the above two.
data_Id, segment_Id, column_1, column_2, ..., column_M

For a data source which has N columns, it will have N/M
records for each message data.

Regards,
Derek

You could think about a data driven design where you simply
add rows to account for new columns. It doesn't address any
of the concerns voiced in previous responses though.
Essentially you end up with a filing system instead of a
database. But that maybe all you need.


Reply With Quote
  #10  
Old   
Tony Rogerson
 
Posts: n/a

Default Re: how to design tables to store random number of columns - 09-13-2006 , 12:47 AM



You really ought to look at using different tables for different
datasources, or are the different datasources pulling in the same entities?

If you want to hold it in one structure you should be looking at XML; SQL
Server 2005 has a fairly good implementation of XML inside the data engine
now and you can index it and have check constraints on the XML schema....

--
Tony Rogerson
SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL
Server Consultant
http://sqlserverfaq.com - free video tutorials


<derek.gtalk (AT) gmail (DOT) com> wrote

Quote:
Hi,

I want to design a generic solution to store different data sources.
One data source may have 10 columns, while the other may have 100+. I
know a few solutions, but none of them seems ideal. Could you give me
some advice? My solutions are listed below:

1. one record only holds one column. so the table will look like:

data_Id, columnId, dataValue

This table may have millions of records easily.

2. put all the columns into one record as below:
data_Id, column_1, column_2, ..., column_N

Obviously we don't know the N in advance. When we got another data
source which has more columns, have to append more columns to the
existing table. The other drawback is that it wastes lots of space for
other data sources whose number of columns is less than N.

3. the solution combines the above two.
data_Id, segment_Id, column_1, column_2, ..., column_M

For a data source which has N columns, it will have N/M records for
each message data.

Regards,
Derek




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.