MYSQL 5.7.5:
You can accomplish the goal using Generated Columns and this.
Not tested
CREATE TABLE TEST (
ProdID VARCHAR(20) AS CONCAT('PR','',PID) STORED,
PID INT auto_increment)
For your convenience,
MSSQL:
The easiest method is to simply make a calculated column. It uses what is known as a "calculated" column in conjunction with an IDENTITY column.
CREATE TABLE Test
(
ProdID AS CAST('PR'+RIGHT('000'+CAST(RowNum AS VARCHAR(3)),3) AS VARCHAR(30)) PERSISTED
,ProdName VARCHAR(30)
,RowNum INT IDENTITY(1,1)
);
INSERT INTO Test (ProdName)
SELECT 'Thread' UNION ALL
SELECT 'Button Thread' UNION ALL
SELECT 'Coat Thread';
SELECT ProdID, ProdName FROM Test;
That returns the following (notice that the auto-increment worked):
ProdID ProdName
------------------------------ ------------------------------
PR001 Thread
PR002 Button Thread
PR003 Coat Thread
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…