Connecting Tech Pros Worldwide Help | Site Map

How to create a table with 300 columns?

Newbie
 
Join Date: Aug 2007
Posts: 3
#1: Aug 28 '07
Hello

I have created tables with 20-30 columns and it was manually writing each line of code even when the col type was the same such as
Expand|Select|Wrap|Line Numbers
  1. create table testexamp(
  2. id varchar (28).
  3. sample1 float(7,3),
  4. sample2 float(7,3),
  5. sample3 float(7,3),
  6. sample4 float(7,3));
But how can I create a table with 300 columns? Is there a proper way other than manually writing each line as in the above example?

Please help
mr
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Aug 28 '07

re: How to create a table with 300 columns?


Heya, MR. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

You may want to rethink your table structure. For example, you can save each sample as its own record:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE
  2.     `testexamp`
  3.     (
  4.         `id`
  5.             VARCHAR(28)
  6.             NOT NULL,
  7.         `sample`
  8.             FLOAT(7,3)
  9.             NOT NULL,
  10.         KEY
  11.         (
  12.             `id`,
  13.             `sample`
  14.         )
  15.     )
  16.  
Each id will then have 300 rows, which is fine because MySQL is good at indexing. You'd just need another script, such as PHP, if you wanted to present your data horizontally.

To answer your question, though, if you want 300 columns, you need to declare all 300 of them.
Newbie
 
Join Date: Aug 2007
Posts: 3
#3: Aug 28 '07

re: How to create a table with 300 columns?


Quote:

Originally Posted by pbmods

Heya, MR. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

You may want to rethink your table structure. For example, you can save each sample as its own record:

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE
  2.     `testexamp`
  3.     (
  4.         `id`
  5.             VARCHAR(28)
  6.             NOT NULL,
  7.         `sample`
  8.             FLOAT(7,3)
  9.             NOT NULL,
  10.         KEY
  11.         (
  12.             `id`,
  13.             `sample`
  14.         )
  15.     )
  16.  
Each id will then have 300 rows, which is fine because MySQL is good at indexing. You'd just need another script, such as PHP, if you wanted to present your data horizontally.

To answer your question, though, if you want 300 columns, you need to declare all 300 of them.

--------------------------------
Hello,

Thank you for your message. I guess there is no nice solution because basically my data is a 16000 x 300 matrix. so, it doesn't help to transpose it..:)
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#4: Aug 28 '07

re: How to create a table with 300 columns?


Heya, MR.

Depends on where your data is coming from. Are you saving the data using another scripting language, such as PHP or ASP?
Newbie
 
Join Date: Aug 2007
Posts: 3
#5: Aug 29 '07

re: How to create a table with 300 columns?


Quote:

Originally Posted by pbmods

Heya, MR.

Depends on where your data is coming from. Are you saving the data using another scripting language, such as PHP or ASP?

----------------------------------------------------------------
Hello

My data is in .txt format. I cannot open it in excel as it exceeds 256 columns. The data itself came from a gene expression scan.

Thank you
mray
Reply