添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

mysql生成uuid主键

76浏览 · 2023-08-25 21:09:54
[mysql](https://geek.csdn.net/educolumn/184b56c51fd333211e6f2a08e35b0efe?spm=1055.2569.3001.10083)生成UUID主键的方法是使用UUID()[函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)。这个[函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)会生成一个全局唯一的标识符,可以用作表的主键。通过在创建表时指定主键类型为CHAR(36),并将默认值设置为UUID(),可以实现自动生成UUID主键。例如,可以使用以下语句创建一个具有UUID主键的表: CREATE TABLE t_uuid ( id CHAR(36) PRIMARY KEY DEFAULT UUID(), r1 INT, KEY idx_r1(r1) 这样,每次插入新记录时,MySQL会自动为id列生成一个唯一的UUID值。\[1\] #### 引用[.reference_title] - *1* *2* [第17期:索引设计(主键设计)](https://blog.csdn.net/ActionTech/article/details/110470533)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chat[gpt](https://geek.csdn.net/educolumn/d2f82220638caf1d7a0d5521eb7b6775?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA5NTQ4NzEwLCJpYXQiOjE3MDg5NDM5MTAsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.Ycp4bmJnbuf-GXluSQA922QiehPy9qQiboAgoDqZFno&spm=1055.2569.3001.10083)_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chat[gpt](https://geek.csdn.net/educolumn/d2f82220638caf1d7a0d5521eb7b6775?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA5NTQ4NzEwLCJpYXQiOjE3MDg5NDM5MTAsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.Ycp4bmJnbuf-GXluSQA922QiehPy9qQiboAgoDqZFno&spm=1055.2569.3001.10083)"}} ] [.reference_item] - *3* [MySQL UUID主键-由PHP或M