How do I create contextual AUTO_INCREMENT in MySql?

前端 未结 1 1185
囚心锁ツ
囚心锁ツ 2020-12-06 09:16

I want to Create a Contextual increment, not sure of term I am using is correct. here is my table

CREATE TABLE IF NOT EXISTS `test` (
  `id` int(10) NOT NULL         


        
相关标签:
1条回答
  • 2020-12-06 09:21

    You've got to swap the order of your indexes:

    CREATE TABLE IF NOT EXISTS `test` (
        `id` int(10) NOT NULL AUTO_INCREMENT,
        `abc` varchar(50) NOT NULL,
        `data` varchar(100) NOT NULL,
        PRIMARY KEY (`abc`, `id`)   -- id got to be second
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
    

    I cite from the manual:

    For MyISAM tables, you can specify AUTO_INCREMENT on a secondary column in a multiple-column index.

    Working example in this fiddle

    0 讨论(0)
提交回复
热议问题