How to make MySQL table primary key auto increment with some prefix

前端 未结 4 515
忘了有多久
忘了有多久 2020-11-22 05:38

I have table like this

table
id Varchar(45) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name CHAR(30) NOT NULL,

I want to increment my id field li

4条回答
  •  心在旅途
    2020-11-22 05:50

    Here is PostgreSQL example without trigger if someone need it on PostgreSQL:

    CREATE SEQUENCE messages_seq;
    
     CREATE TABLE IF NOT EXISTS messages (
        id CHAR(20) NOT NULL DEFAULT ('message_' || nextval('messages_seq')),
        name CHAR(30) NOT NULL,
    );
    
    ALTER SEQUENCE messages_seq OWNED BY messages.id;
    

提交回复
热议问题