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)
)