Stax
Tools

ตัวสร้าง UUID

สร้าง UUID v4 (สุ่ม) และ v7 (มี timestamp) ทันที

Click Generate to create UUID v4 values
Generated using crypto.randomUUID() — cryptographically secure random values. UUID v4 has 122 bits of randomness; collision probability is negligible.

UUID ถูกนำไปใช้เพื่ออะไร

เวอร์ชันของ UUID

UUID แก้ปัญหาการสร้าง unique identifier ในระบบ distributed โดยไม่ต้องมีตัวประสานงานกลาง ต่างจาก ID ฐานข้อมูลแบบ auto-increment UUID สามารถสร้างได้จาก client ทุกตัว ออฟไลน์ และไม่มีความเสี่ยงต่อการชนกัน

UUID มีหลายเวอร์ชัน v1 มี timestamp และ MAC address v3 และ v5 เป็นแบบ namespace (กำหนดผลลัพธ์จาก input) v4 สุ่มอย่างสมบูรณ์ — เป็นที่นิยมใช้มากที่สุด v7 (ใหม่กว่า) เรียงตามเวลาและสุ่ม เหมาะสำหรับประสิทธิภาพ index ฐานข้อมูล

เครื่องกำเนิดนี้สร้าง UUID v4 โดยใช้ crypto.randomUUID() — การ implement ด้วย CSPRNG ของเบราว์เซอร์

นักพัฒนา backend สร้าง UUID ทดสอบเพื่อ seed ฐานข้อมูลระหว่างการพัฒนาโดยไม่ต้องรัน database เพื่อสร้าง auto-increment ID วิศวกร QA สร้าง UUID สำหรับ test fixture ที่ต้องการ identifier ที่เสถียรและ unique ตลอดการรัน architect ที่ออกแบบระบบ SaaS multi-tenant ใช้ UUID แทน auto-increment ID เพื่อป้องกันการโจมตีแบบ enumeration — หาก ID เป็น sequential ผู้ไม่ประสงค์ดีสามารถวนซ้ำผ่านทุก record ได้ UUID ทำให้สิ่งนี้เป็นไปไม่ได้ data engineer ใช้ UUID v4 เป็น partition key ในฐานข้อมูล distributed (Cassandra, DynamoDB) เพื่อหลีกเลี่ยง hot partition

UUID v4 สุ่มอย่างสมบูรณ์ — ดีเยี่ยมสำหรับความ unique แต่ประสิทธิภาพ index ฐานข้อมูลต่ำเพราะการ insert แบบสุ่มทำให้เกิด B-tree page split UUID v7 (RFC 9562) เพิ่ม timestamp ระดับมิลลิวินาทีไว้ที่ส่วนต้นของ UUID ทำให้เรียงตามเวลาได้และดีกว่ามากสำหรับการ insert ฐานข้อมูลแบบ sequential หากคุณกำลังสร้างระบบใหม่ในปี 2025 และฐานข้อมูลรองรับ UUID v7 (PostgreSQL 17+, MySQL 8.0.35+) ควรใช้ v7 สำหรับ primary key สำหรับระบบเก่า API token และกรณีที่ไม่ใช่ฐานข้อมูล v4 ยังเป็นมาตรฐานอยู่

ใช้ bulk mode เพื่อสร้าง UUID ได้ถึง 50 ตัวในครั้งเดียว ปุ่ม “Copy All” คัดลอกทั้งหมดเป็นลิสต์คั่นด้วยบรรทัดใหม่ พร้อมวางลง SQL INSERT script, seed file หรือ spreadsheet สลับปิดตัวเลือก hyphen หากฐานข้อมูลเก็บ UUID เป็น string 32 ตัวอักษร (พบบ่อยใน MySQL ประเภท CHAR(32)) สลับเป็นตัวพิมพ์ใหญ่หากระบบของคุณต้องการ hex ตัวพิมพ์ใหญ่ (Oracle และ SQL Server schema รุ่นเก่าบางตัว)

  • Primary key ฐานข้อมูล — โดยเฉพาะในระบบ distributed หรือ multi-tenant
  • API key และ token — เป็นฐานสำหรับการอ้างอิง unique
  • ชื่อไฟล์ — หลีกเลี่ยงการชนกันในการอัปโหลดแบบ multi-user
  • Session ID และ correlation ID — สำหรับการติดตาม request
  • ID ที่สร้างจาก frontend — สำหรับ optimistic UI update ก่อนยืนยันจากเซิร์ฟเวอร์

คำถามที่พบบ่อย

What is a UUID?
UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify objects in computer systems. The standard format is 8-4-4-4-12 hexadecimal digits separated by hyphens, e.g. 550e8400-e29b-41d4-a716-446655440000.
What is UUID v4?
UUID v4 is randomly generated — 122 bits of randomness with a small portion reserved for version and variant bits. It requires no coordination between systems, making it ideal for distributed databases, frontend IDs, and API keys.
Are these UUIDs truly unique?
The probability of generating two identical v4 UUIDs is astronomically small — roughly 1 in 5.3 × 10^36. For practical purposes in any application, they are effectively guaranteed unique.
Is crypto.randomUUID() safe to use?
Yes. crypto.randomUUID() uses the browser's cryptographically secure pseudorandom number generator (CSPRNG), the same source used for cryptographic operations. It is significantly more random than Math.random().
When should I use UUID without hyphens?
Some databases and APIs prefer the compact 32-character hex string without hyphens (e.g., MySQL's UNHEX for binary storage, some REST APIs). Both formats represent the same value — the hyphens are just separators for readability.

เครื่องมือที่เกี่ยวข้อง