Last active
August 29, 2015 14:13
-
-
Save kou/8346678eb597750ceb21 to your computer and use it in GitHub Desktop.
マルチカラムなunique key
This file contains hidden or 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 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