When should I use UNSIGNED and SIGNED INT in MySQL?

后端 未结 8 845
后悔当初
后悔当初 2020-12-07 12:45

When should I use UNSIGNED and SIGNED INT in MySQL ? What is better to use or this is just personal prefernce ? Because I\'ve seen it used like this;

id INT         


        
相关标签:
8条回答
  • 2020-12-07 13:14

    If you know the type of numbers you are going to store, your can choose accordingly. In this case your have 'id' which can never be negative. So you can use unsigned int. Range of signed int: -n/2 to +n/2 Range of unsigned int: 0 to n So you have twice the number of positive numbers available. Choose accordingly.

    0 讨论(0)
  • 2020-12-07 13:16

    One thing i would like to add In a signed int, which is the default value in mysql , 1 bit will be used to represent sign. -1 for negative and 0 for positive. So if your application insert only positive value it should better specify unsigned.

    0 讨论(0)
提交回复
热议问题