좋은 프로그램은 마음의 여유에서 나온다.
mysql sequence 흉내내기 본문
특정값기준으로 자동증가 하고싶을경우 사용하면 좋을듯..
출처 : http://blog.naver.com/PostView.nhn?blogId=deepblue28&logNo=140171138992
http://stackoverflow.com/questions/3347811/mysql-custom-sequence-generator-like-oracle
http://dev.mysql.com/doc/refman/5.1/en/example-auto-increment.html
MYISAM 만 된다는거..
CREATE TABLE component_core ( component_id INT AUTO_INCREMENT, PRIMARY KEY(component_id) );
CREATE TABLE component_history ( component_id INT NOT NULL, version_id INT AUTO_INCREMENT, DATA VARCHAR(20), version_start_date DATETIME NOT NULL, version_end_date DATETIME NOT NULL, PRIMARY KEY(component_id,version_id) ) ENGINE=MYISAM;
INSERT INTO component_core () VALUES (); INSERT INTO component_core () VALUES ();
INSERT INTO component_history (component_id, DATA, version_start_date, version_end_date) VALUES (1, 'data', NOW(), NOW()); INSERT INTO component_history (component_id, DATA, version_start_date, version_end_date) VALUES (1, 'data', NOW(), NOW()); INSERT INTO component_history (component_id, DATA, version_start_date, version_end_date) VALUES (1, 'data', NOW(), NOW());
INSERT INTO component_history (component_id, DATA, version_start_date, version_end_date) VALUES (2, 'data', NOW(), NOW()); INSERT INTO component_history (component_id, DATA, version_start_date, version_end_date) VALUES (2, 'data', NOW(), NOW()); INSERT INTO component_history (component_id, DATA, version_start_date, version_end_date) VALUES (2, 'data', NOW(), NOW()); |
SELECT * FROM component_history;
component_id version_id data version_start_date version_end_date 1 1 data 2012-10-25 12:40:22 2012-10-25 12:40:22 1 2 data 2012-10-25 12:40:26 2012-10-25 12:40:26 1 3 data 2012-10-25 12:40:26 2012-10-25 12:40:26 2 1 data 2012-10-25 12:40:45 2012-10-25 12:40:45 2 2 data 2012-10-25 12:40:46 2012-10-25 12:40:46 2 3 data 2012-10-25 12:40:47 2012-10-25 12:40:47 |
'데이터베이스 > MySql,maria' 카테고리의 다른 글
우분투 mysql 설치 (0) | 2015.04.24 |
---|---|
mysql 외부접속 에러 host is not allowed ~~~ (1) | 2013.11.21 |
mysql 외부 접속 안될 때 (0) | 2013.11.21 |
mysql index btree/hash 차이 (0) | 2012.11.13 |
mysql 최소한의 보안설정. (0) | 2012.10.31 |