clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3798988 fiddles created (41854 in the last week).

CREATE TABLE test (NAME CHAR(1), REV INT, ID INT, PI CHAR(5), CHECK (PI = 'PA' + FORMAT(ID, '000')));
 hidden batch(es)


INSERT INTO test VALUES ('A', 0, 1, 'PA001');
1 rows affected
 hidden batch(es)


INSERT INTO test VALUES ('A', 1, 1, 'PA001');
1 rows affected
 hidden batch(es)


INSERT INTO test VALUES ('A', 2, 1, 'PA002');
Msg 547 Level 16 State 0 Line 1 The INSERT statement conflicted with the CHECK constraint "CK__test__35BCFE0A". The conflict occurred in database "fiddle_440e019e5d3d412583c4ab74dcc4d474", table "dbo.test". Msg 3621 Level 0 State 0 Line 1 The statement has been terminated.
 hidden batch(es)


INSERT INTO test VALUES ('A', 1, 2, 'PA001');
Msg 547 Level 16 State 0 Line 1 The INSERT statement conflicted with the CHECK constraint "CK__test__35BCFE0A". The conflict occurred in database "fiddle_440e019e5d3d412583c4ab74dcc4d474", table "dbo.test". Msg 3621 Level 0 State 0 Line 1 The statement has been terminated.
 hidden batch(es)


INSERT INTO test VALUES ('A', 1, 2, 'PA002');
1 rows affected
 hidden batch(es)


INSERT INTO test VALUES ('A', 1, 999, 'PA999');
1 rows affected
 hidden batch(es)


SELECT * FROM test
NAME REV ID PI
A 0 1 PA001
A 1 1 PA001
A 1 2 PA002
A 1 999 PA999
 hidden batch(es)