Skip to content

Instantly share code, notes, and snippets.

@ugdark
Last active December 21, 2015 17:39
Show Gist options
  • Save ugdark/6342411 to your computer and use it in GitHub Desktop.
Save ugdark/6342411 to your computer and use it in GitHub Desktop.
サンプルSQL
CREATE TABLE IF NOT EXISTS `user_cards` (
`id` int(11) NOT NULL COMMENT 'ID',
`user_id` int(11) NOT NULL COMMENT 'ユーザーID',
`card_id` int(11) NOT NULL COMMENT 'カードID',
`created_at` datetime NOT NULL COMMENT '作成日時',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新日時',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_key` (`user_id`,`card_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='ユーザーが保持してるカード一覧';
@ugdark
Copy link
Author

ugdark commented Aug 26, 2013

user_id のみかuser_id+card_idのみしか検索なし前提。

@ugdark
Copy link
Author

ugdark commented Aug 26, 2013

CREATE TABLE IF NOT EXISTS user_cards (
id int(10) unsigned NOT NULL COMMENT 'ID',
user_id int(10) unsigned NOT NULL COMMENT 'ユーザーID',
card_id int(10) unsigned NOT NULL COMMENT 'カードID',
created_at datetime NOT NULL COMMENT '作成日時',
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新日時',
PRIMARY KEY (id),
UNIQUE KEY unique_key (user_id,card_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='ユーザーが保持してるカード一覧';
unsigned ならint(10)

@ugdark
Copy link
Author

ugdark commented Aug 26, 2013

utf8mb4 にするとiOSの絵文字に対応できてなお良いとのこと。。また調べよっと

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