Skip to content

Instantly share code, notes, and snippets.

@kobitoDevelopment
Last active February 2, 2026 13:21
Show Gist options
  • Select an option

  • Save kobitoDevelopment/bad1542cb3519226f0b490b519caf7c5 to your computer and use it in GitHub Desktop.

Select an option

Save kobitoDevelopment/bad1542cb3519226f0b490b519caf7c5 to your computer and use it in GitHub Desktop.
CREATE TABLE users (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,  -- 内部用(高速)
    uuid BINARY(16) NOT NULL UNIQUE,                 -- 外部公開用
    name VARCHAR(255),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    
    INDEX idx_uuid (uuid)
);

-- 挿入
INSERT INTO users (uuid, name) 
VALUES (UUID_TO_BIN(UUID(), 1), 'Taro');

使い分け

内部JOIN・FK: id (BIGINT) APIレスポンス: uuid URL: /users/{uuid} ログ・デバッグ: id でも uuid でもどちらでも可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment