Question

I make db table in mysql.

create table finaltest1(id int(10),title text(20), category text(20), price text(10), ymd text(15), iconurl text(50), screenshoturl text(150), appid text(15), company text(30), capacity text(15));

but text column's length is all 0. Why?

Was it helpful?

Solution

As swati has already said, you need to learn the MySQL String Data Types. If you use TinyText, the column will always take up 256 bytes, even if it's empty. You should note that with the *Text column types you cannot have default values.

If you use a VARCHAR(20) column, the actual data space used depends on the contents, and you can have defaults.

OTHER TIPS

If you want limited text with field then use datatype VARCHAR (20) . Else for long text use simply TEXT datatype .

check : http://www.htmlite.com/mysql003.php

The length given by you 20 is comes under the TINYTEXT .

TINYTEXT    256 bytes    
TEXT        65,535 bytes            ~64kb
MEDIUMTEXT  16,777,215 bytes        ~16MB
LONGTEXT    4,294,967,295 bytes     ~4GB

text doesn't need a length. Learn more from documentation. The following query should work.

create table finaltest1(id int(10),
    title text,
    category text,
    price text,
    ymd text,
    iconurl text,
    screenshoturl text,
    appid text,
    company text,
    capacity text
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top