The ID of Google analytics is generally like: ua-18xxxxx-1, ua-18xxxxx-4, we can divide it into two segments: field 1:ua-18xxxxx refers to the ID of the account Field 2:1, 4 appended to field 1, respectively, refers to two sites under the account name. There was a time to struggle with such an ID how to maintain, until recently checked to the MySQL manual only found that the original MySQL is very good support for this kind of automatic growth field of composite primary key, so field 2 is the storage engine automatically calculated. Calculation method: MAX (auto_increment_column) + 1 WHERE prefix=given-prefix [1].
Not much to say, look directly at SQL:
mysql> create table ' _test ' ( -> ' C1 ' varchar (20) NOT NULL DEFAULT ', -- primary key one:varchar -> ' C2 ' int (one) NOT NULL AUTO_INCREMENT, -- primary key two: auto-increment sequence -> ' C3 ' varchar (255) , -> PRIMARY KEY (' C1 ', ' C2 ') -- Note the sequencing here -> ) ENGINE=MyISAM DEFAULT CHARSET=latin1; query ok, 0 rows affected (0.04 sec) Mysql>mysql> insert into ' _test ' (' C1 ', ' C3 ') VALUES (' AAA ', ' Robin home '), -> ( ' AAA ', ' Robin blog '), -> (' AAA ', ' robin resume '), -> (' BBB ', ' Lily home '), -> (' BBB ', ' lily blog '); Query ok, 5 rows affected (0.00 sec) records: 5 duplicates: 0 warnings: 0mysql>mysql > SELECT * FROM ' _test '; +-----+----+--------------+| c1 | c2 | c3 |+-----+----+--------------+| aaa | 1 | robin home | | aaa | 2 | robin blog | | aaa | 3 | robin resume | | bbb | 1 | lily home | | bbb | 2 | lily blog |+-----+----+--------------+5 rows in set (0.00 sec) mysql>
It is worth noting that this feature of MySQL only applies to the MyISAM and BDB engines.
MySQL Composite primary key self-growing field