简体   繁体   中英

When should I use UNSIGNED and SIGNED INT in MySQL?

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(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

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(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

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(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

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(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

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(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

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(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

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(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

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(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

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(10) UNSIGNED NOT NULL AUTO_INCREMENT

and

id INT(11) NOT NULL AUTO_INCREMENT

If you wanna keep it simply, then you have to keep in mind if you want to calculate with these numbers as well (subtraction). If you for example calculate A - B and B is bigger than A, you can get in trouble. There you would have to CAST the SIGNED number to a UNSIGNED.

You can read more about this for example here: BIGINT UNSIGNED VALUE IS out of range My SQL

Use the unsigned if u not need use foreign this field on current table. I was have next problem:

General error: 3780 Referencing column 'event_id' and referenced column 'id' in foreign key constraint 'events_event_id_foreign' are incompatible. (SQL: alter table `events` add constraint `events_event_id_foreign` foreign key (`event_id`) references `users` (`id`) on delete cascade)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM