clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1582857 fiddles created (20323 in the last week).

-- option 1 Create table badge( id INT AUTO_INCREMENT, name VARCHAR (20) NOT NULL, code CHAR (3) AS (SUBSTRING(name,1,2)), -- concat on id auto increment does not work PRIMARY KEY (ID) ) ;
 hidden batch(es)


-- option 2 Create table badge1( id INT, name VARCHAR(20) NOT NULL, code CHAR(3) AS (concat(SUBSTRING(name,1,2),id)), PRIMARY KEY (ID) )
 hidden batch(es)


insert into badge (name) values ('myname')
 hidden batch(es)


insert into badge1 (id,name) values (1,'myname')
 hidden batch(es)


select id,name,concat(code,id) code from badge
id name code
1 myname my1
 hidden batch(es)


select id,name,code from badge1
id name code
1 myname my1
 hidden batch(es)