Last active
December 21, 2015 17:39
-
-
Save ugdark/6342411 to your computer and use it in GitHub Desktop.
サンプルSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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='ユーザーが保持してるカード一覧'; |
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)
utf8mb4 にするとiOSの絵文字に対応できてなお良いとのこと。。また調べよっと
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
user_id のみかuser_id+card_idのみしか検索なし前提。