CREATE TRIGGER generateCode ON dbo.TEACHER 
FOR INSERT AS
if exists(select 1 from inserted where isnull(CODE,'')='')
update TEACHER set TEACHER_CODE = 50000 + i.ID
from TEACHER a,inserted i 
where a.ID = i.ID and isnull(a.CODE,'')=''