Best Type Mysql to count the accesses

Asked

Viewed 45 times

1

I have a database where it contains PDF files, only I’m willing to count how many views this file had. The accounting structure is ready, because it was done in PHP/Mysql, but I have a question. Normally I put the Varchar type(255), but for this type it is ideal to do this count? At each access, I will use the UPDATE.

  • 2

    The person who negatived, could you at least say the reason? After all it is a doubt that refers to programming.

  • 1

    If I understood correctly you want to store the total views, ie a number. Why the column would not be bigint?

  • Hello rLinhares. Right. She would accept the sum of each access? Ie. At each access, I would have to add + 1, because I never used this type.

  • 2

    If you want to calculate (sum / subtraction and etc) a value, it must be in a numerical column and not in a VARCHAR, as mentioned by @rLinhares the right is bigint, Integer or any on the same line.

  • Right. I’ll take your cue. Thank you all.

  • Yes, it’s a numerical field, would be no problem

  • 1

    Ask a forced "bit", perhaps it would be better to add/ask the disadvantages in using avarchar instead of a int

Show 2 more comments

1 answer

4


Counting is numerical, and are integer and positive values.

The appropriate type for this, therefore, is INTEGER UNSIGNED (whole WITHOUT sign). In this family, we have these possibilities:

TIPO        BYTES   SIGNED                        UNSIGNED
=========== ======= ============================= =====================
TINYINT     1       de -128 a 127                 de 0 a 255
SMALLINT    2       de -32768 a 32767             de 0 a 65535
MEDIUMINT   3       de -8388608 a 8388607         de 0 a 16777215
INT         4       de -2147483648 a 2147483647   de 0 a 4294967295
BIGINT      8       de -2^63 a 2^63-1             de 0 a 2^64-1

Choose the type that best suits your case, providing the maximum number you want to store.

More details in the manual:

https://dev.mysql.com/doc/refman/5.7/en/integer-types.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.