sqlÖеÄidÊôÓÚʲôÊý¾ÝÀàÐÍ
id ÔÚ sql ÖÐͨ³£ÊÇÕûÊýÀàÐÍ£¬°üÀ¨ int¡¢unsigned int ºÍ bigint£¬»ò char(36) ×Ö·û×ֶΡ£Ñ¡Ôñʱ˼Á¿Ô¤ÆÚÖµ¹æÄ£¡¢´æ´¢¿Õ¼ä¡¢´¦Öóͷ£ËÙÂʺÍΨһÐÔÒªÇó¡£int »ò unsigned int Êdz£¼ûÑ¡Ôñ£¬bigint ÓÃÓÚ´¦Öóͷ£¼«´ó»ò¼«Ð¡Öµ£¬char(36) ÓÃÓÚ´æ´¢ uuid µÈΨһ±êʶ·û¡£
SQL ÖÐ ID µÄÊý¾ÝÀàÐÍ
ÔÚ SQL ÖУ¬ID Ò»Ñùƽ³£ÊÇÒ»¸öÕûÐÍÊý¾ÝÀàÐÍ£¬È磺
ÕûÊý (INT)£ºÒ»ÖÖ´ø·ûºÅµÄ 32 λÕûÊý£¬¿É´æ´¢´Ó -2^31 (-2,147,483,648) µ½ 2^31-1 (2,147,483,647) µÄÖµ¡£
ÎÞ·ûºÅÕûÊý (UNSIGNED INT)£ºÒ»ÖÖ²»´ø·ûºÅµÄ 32 λÕûÊý£¬¿É´æ´¢´Ó 0 µ½ 2^32-1 (4,294,967,295) µÄÖµ¡£
±ðµÄ£¬ID »¹¿ÉÒÔÊÇbigint »ò char(36) ÀàÐÍ£º
bigint£ºÒ»ÖÖ´ø·ûºÅµÄ 64 λÕûÊý£¬¿É´æ´¢´Ó -2^63 (-9,223,372,036,854,775,808) µ½ 2^63-1 (9,223,372,036,854,775,807) µÄÖµ¡£
char(36)£ºÒ»ÖÖÀο¿³¤¶ÈµÄ×Ö·û×ֶΣ¬¿É´æ´¢³¤¶ÈΪ 36 ¸ö×Ö·ûµÄ×Ö·û´®¡£Í¨³£ÓÃÓÚ´æ´¢ UUID »òÀàËÆΨһ±êʶ·û¡£
Ñ¡ÔñºÏÊʵÄÊý¾ÝÀàÐÍ
Ñ¡Ôñ id Êý¾ÝÀàÐÍʱÐèҪ˼Á¿ÒÔÏÂÒòËØ£º
Ô¤ÆÚÖµ¹æÄ££ºÈ·¶¨Ô¤ÆÚÖµµÄ¹æÄ£ÒÔÑ¡ÔñºÏÊʵÄÊý¾ÝÀàÐÍ¡£
´æ´¢¿Õ¼ä£ºÎÞ·ûºÅÕûÊý±ÈÓзûºÅÕûÊýÕ¼ÓøüÉٵĴ洢¿Õ¼ä¡£
´¦Öóͷ£ËÙÂÊ£ºÕûÊý±È×Ö·û×ֶθü¿ìµØ¾ÙÐнÏÁ¿ºÍ²Ù×÷¡£
ΨһÐÔÒªÇó£ºUUID »ò CHAR(36) ¿ÉÓÃÓڴ洢Ψһ±êʶ·û¡£
Ò»Ñùƽ³£ÇéÐÎÏ£¬INT »ò UNSIGNED INT ÊÇ id ×ֶεij£¼ûÑ¡Ôñ¡£¿ÉÊÇ£¬ÔÚÐèÒª´¦Öóͷ£ºÜÊÇ´ó»òºÜÊÇСµÄÊý×Ö»òÐèҪΨһÐÔʱ£¬BIGINT »ò CHAR(36) ¿ÉÄܸüºÏÊÊ¡£
ÒÔÉϾÍÊÇsqlÖеÄidÊôÓÚʲôÊý¾ÝÀàÐ͵ÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡