MySQL Type questions
#1

Hi guys

I have few question's about MySQL types.

I'm really try to find tutorial for MySQL types for this what i need but without success.

1. When to use TinyInt,SmallInt,MediumInt,BigInt ? Because I use every time int(11)-for everything,is this wrong?

I'm find this:

Код:
tinyint: 1 byte, -128 to +127 / 0 to 255 (unsigned)
smallint: 2 bytes, -32,768 to +32,767 / 0 to 65,535 (unsigned)
mediumint: 3 bytes, -8,388,608 to 8,388,607 / 0 to 16,777,215 (unsigned)
int/integer: 4 bytes, -2,147,483,648 to +2,147,483,647 / 0 to 4,294,967,295 (unsigned)
bigint: 8 bytes, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 / 0 to 18,446,744,073,709,551,615 (unsigned)
Now i don't understand what means int(11) ?


2. When is better to use text then varchar?
For example for 128 string i use varchar(12,is this wrong?Is better to use text or?
Reply
#2

inside the bracket is the size in Bytes. Those are not MYSQL Types as ****** said. They are data-types. You can check on MySQL Wiki to see the size limits of all database. The more you put size, more memory it occupies in RAM. So make sure, not to use extra size inside your variables. Its called Memory Optimization.
Reply
#3

Quote:
Originally Posted by GTLS
Посмотреть сообщение
inside the bracket is the size in Bytes. Those are not MYSQL Types as ****** said. They are data-types. You can check on MySQL Wiki to see the size limits of all database. The more you put size, more memory it occupies in RAM. So make sure, not to use extra size inside your variables. Its called Memory Optimization.
actually that's just the display size. it will always occupy the size of whatever the specified type is
Reply
#4

11 there means number of numeric characters width.. integer has 11 digits including the sign e.g. -2147483647 while unsigned integer only has 10 digits since it has no negative sign e.g. 4294967295

Integer in pawn has size of 4 bytes, within range of -2,147,483,648 (cellmin) to 2,147,483,647 (cellmax), so it will be just always fine when you store this variable to your database field in data type integer (11).

Varchar means variable length character, the string you are storing would occupy same size of the bytes (depending on the charset) plus 1, e.g.
"Hello" -> 5 characters = 6 bytes
And 128 is just the maximum size of string you want to store in the field. so you can't store longer string.

Text has a fixed width/size, if you put Text (128) that will just use 128 bytes for each field, e.g.
"Hello" -> 5 characters = 128 bytes (depends on charset)
The advantage is this will be faster to use, but consumes more memory.

Just go find documentation for "mysql data types"
https://dev.mysql.com/doc/refman/5.7/en/data-types.html

You can read that references for your usage in MySQL database.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)