CREATE TABLE document_control (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
name VARCHAR(10)
);
CREATE TABLE document_control (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT...
INSERT INTO document_control
SELECT CONCAT_WS('-', RIGHT(YEAR(CURRENT_TIMESTAMP), 2), LPAD(COUNT(*) + 1, 3, 0))
FROM document_control
WHERE LEFT(id_custom, 2) = RIGHT(YEAR(CURRENT_TIMESTAMP), 2)