Add according CHECK constraint:
CREATE TABLE {tablename} ( {table definition},
CHECK (ID != 1 OR PI = 'PA001') )
CREATE TABLE test (NAME CHAR(1), REV INT, ID INT, PI CHAR(5),
CHECK (ID != 1 OR PI = 'PA001'));
GO
INSERT INTO test VALUES ('A', 0, 1, 'PA001');
GO
INSERT INTO test VALUES ('A', 1, 1, 'PA001');
GO
INSERT INTO test VALUES ('A', 2, 1, 'PA002');
GO
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_c4abb5f9c518435fb6f88f2215747a89", table "dbo.test".
Msg 3621 Level 0 State 0 Line 1
The statement has been terminated.
db<>fiddle here
that table and data is example ID has any data when match data so pi, not any value exam id 1 PI = PA001, id 2 PI = PA002, id 999 PI = PA011 – พิมพ์ชดารัตน์ เนตรวานิช
Alter CHECK constraint accordingly.
CHECK (PI = 'PA' + FORMAT(ID, '000'))
https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=958a54cb5dcd060a54561bd09105eabf