如何使用前缀使MySQL表主键自动递增我有这样的桌子tableid Varchar(45) NOT NULL AUTO_INCREMENT PRIMARY KEY,name CHAR(30) NOT NULL,我想增加我的id字段,就像'LHPL001','LHPL002','LHPL003'..等等,我该怎么做?请告诉我任何可能的方法。
3 回答
冉冉说
TA贡献1877条经验 获得超1个赞
ZEROFILL
LPAD
CONCAT
create table so ( id int(3) unsigned zerofill not null auto_increment primary key, name varchar(30) not null);insert into so set name = 'John';insert into so set name = 'Mark';select concat('LHPL', id) as id, name from so;+---------+------+| id | name |+---------+------+| LHPL001 | John || LHPL002 | Mark |+---------+------+
create table so ( id int unsigned not null auto_increment primary key, name varchar(30) not null);insert into so set name = 'John';insert into so set name = 'Mark';select concat('LHPL', LPAD(id, 3, 0)) as id, name from so;+---------+------+| id | name |+---------+------+| LHPL001 | John || LHPL002 | Mark |+---------+------+
添加回答
举报
0/150
提交
取消