creating primary key based on date

前端 未结 4 609
南方客
南方客 2020-12-07 05:05

I am trying to create a unique ID for each record based on the date the record is created. Example, if the record is created today, I want the key to be 20101130XX where XX

4条回答
  •  被撕碎了的回忆
    2020-12-07 05:37

    What will you do if the number of entries per day exceeds 99? If you strongly want to use "20101130XX" index, I would recommend you use a compound key:

    CREATE TABLE `test` (
      `date` date NOT NULL,
      `id` tinyint(4) NOT NULL,
      `other_fields` varchar(255) DEFAULT NULL,
      PRIMARY KEY (`date`,`id`)
    );
    

提交回复
热议问题