Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I have to set the max length of every single text column in the database?

Why is it that every RDBMS insists that you tell it what the max length of a text field is going to be... why can't it just infer this information form the data that's put into the database?

I've mostly worked with MS SQL Server, but every other database I know also demands that you set these arbitrary limits on your data schema. The reality is that this is not particulay helpful or friendly to work with becuase the business requirements change all the time and almost every day some end-user is trying to put a lot of text into that column.

Does any one with some inner working knowledge of a RDBMS know why we just don't infer the limits from the data that's put into the storage? I'm not talking about guessing the type information, but guessing the limits of a particular text column.

I mean, there's a reason why I don't use nvarchar(max) on every text column in the database.

like image 512
John Leidegren Avatar asked May 19 '10 13:05

John Leidegren


People also ask

What is maximum length of text field in database?

A TEXT column with a maximum length of 65,535 (216 − 1) characters. The effective maximum length is less if the value contains multibyte characters.

What is the maximum length of the long text data type?

Long Text In Access web apps, the Long Text field can store up to 2^30-1 bytes, and is equivalent to the SQL Server data type of nvarchar(max). If you want, you can set a character limit to prevent your users from using the full capacity of the field.

What is the maximum length of a table name?

For logical table names stored within an Entry table, you can have up to 40 characters. Form names are limited to 100 characters, which is also the Library manager limit on any file name. Section names are limited to 64 characters.


1 Answers

Because computers (and databases) are stupid. Computers don't guess very well and, unless you tell them, they can't tell that a column is going to be used for a phone number or a copy of War and Peace. Obviously, the DB could be designed to so that every column could contain an infinite amount of data -- or at least as much as disk space allows -- but that would be a very inefficient design. In order to get efficiency, then, we make a trade-off and make the designer tell the database how much we expect to put in the column. Presumably, there could be a default so that if you don't specify one, it simply uses it. Unfortunately, any default would probably be inappropriate for the vast majority of people from an efficiency perspective.

like image 112
tvanfosson Avatar answered Sep 28 '22 07:09

tvanfosson