Skip to content

Instantly share code, notes, and snippets.

@kou
Last active August 29, 2015 14:13
Show Gist options
  • Save kou/8346678eb597750ceb21 to your computer and use it in GitHub Desktop.
Save kou/8346678eb597750ceb21 to your computer and use it in GitHub Desktop.
マルチカラムなunique key
CREATE TABLE articles (
blog_id int,
article_id int,
unique key (blog_id, article_id)
) engine = mroonga default charset = utf8;
INSERT INTO articles VALUES (1, 100);
UPDATE articles SET blog_id = 2;
SELECT * FROM articles;
-- +---------+------------+
-- | blog_id | article_id |
-- +---------+------------+
-- | 2 | 100 |
-- +---------+------------+
-- 1 row in set (0.00 sec)
SELECT * FROM articles WHERE blog_id = 1;
-- Empty set (0.00 sec)
SELECT * FROM articles WHERE blog_id = 2;
-- +---------+------------+
-- | blog_id | article_id |
-- +---------+------------+
-- | 2 | 100 |
-- +---------+------------+
-- 1 row in set (0.00 sec)
SELECT * FROM articles WHERE blog_id = 2 ORDER BY article_id;
-- +---------+------------+
-- | blog_id | article_id |
-- +---------+------------+
-- | 2 | 100 |
-- +---------+------------+
-- 1 row in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment