Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum number of columns in a table

Problem1: What is the maximum no of columns we can have in a table

Problem2: What is the maximum no of columns we should have in a table

like image 937
Asad Avatar asked Jan 11 '10 20:01

Asad


People also ask

What is maximum count of columns a table can have?

Column Count Limits MySQL has hard limit of 4096 columns per table, but the effective maximum may be less for a given table.

How many columns should be in a table?

There is no precise guidance. A table could be as little as one column or as many as the max, 1024. However, in general, you'll probably see no more than 10-15 columns in a table in a well normalized database.

What is the maximum number of columns in SQL Server?

Maximum number of rows & columns in Excel Excel supports three Worksheets in a Workbook file, and each Worksheet can support up to 1,048,576 rows and 16,384 columns of data.


1 Answers

Answer 1: Probably more than you have, but not more than you will grow to have.

Answer 2: Fewer than you have.

Asking these questions usually indicates that you haven't designed the table well. You probably are practicing the Metadata Tribbles antipattern. The columns tend to accumulate over time, creating an unbounded set of columns that store basically the same type of data. E.g. subtotal1, subtotal2, subtotal3, etc.

Instead, I'm guessing you should create an additional dependent table, so your many columns become many rows. This is part of designing a proper normalized database.

CREATE TABLE Subtotals (
  entity_id    INT NOT NULL,
  year_quarter SMALLINT NOT NULL, -- e.g. 20094
  subtotal NUMERIC(9,2) NOT NULL,
  PRIMARY KEY (entity_id, year_quarter),
  FOREIGN KEY (entity_id) REFERENCES Entities (entity_id)
);

My former colleague also wrote a blog about this:

Understanding the maximum number of columns in a MySQL table

The answer is not so straightforward as you might think.

like image 146
Bill Karwin Avatar answered Nov 02 '22 10:11

Bill Karwin