V
V
Vladimir2017-02-28 19:00:26
MySQL
Vladimir, 2017-02-28 19:00:26

Should I put unsigned for fields in MySQL?

Good day! Interested in this question. I watch a lot of tutorials and always use for the id field which will be used as the primary key int(11). I think that this is not correct, since I know that id cannot be negative and it makes sense to do int(10) unsigned, here is the information that I read on the spravkaweb.ru website, it clearly says that "Counting the sequence of numbers for AUTO_INCREMENT starts from 1. This can only be positive numbers. (but even that site uses int(11)). I understand that there may be more than two billion indexes in few places, but I still stick to unsigned. Tell me experts why they do this? Maybe I don't understand. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2017-02-28
@Stalker_RED

At first, you watch what lessons are not clear, and then you are surprised.

Use the UNSIGNED attribute if possible to allow a greater range.
© https://dev.mysql.com/doc/refman/5.7/en/example-au...
Because they are too lazy to write UNSIGNED? Because now even noobs make guides?
Or maybe because they do not want to fill the heads of beginners with unnecessary details? Do you really think that your database will exceed 2 billion records very soon and you will need all 4?
If yes, then here's a hint: with BIGINT, you can raise the bar another 4 billion times.

D
Dmitry MiksIr, 2017-02-28
@miksir

1. Not all bases can unsigned.
2. The primary key can be negative, why not, you can add it by hand.
3. unsigned can cause problems with a programming language that does not have unsigned types and the same size as int.
4. And most importantly - don't care

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question