Think I figured it out ... it appears to be an issue with how disable_ri_check does not interact with previously cached query plans (eg, when statement cache enabled).
My dataserver has statement cache enabled.
If the dataserver doesn't (re)compile my second insert statement then the optimizer uses the query plan from the first insert statement; since the first insert statement failed, the second statement also fails due to re-using the query plan of the first insert.
If I can get the dataserver to (re)compile my second insert statement then it succeeds. A few different ways to get the second insert to succeed:
==================
insert t2 values (1,5)
go
set disable_ri_check on
go
insert t2 values(1,5)
go
!! succeeds since the parser thinks these are 2 different
commands (1st query has a space after 'values')
==================
insert t2 values (1,5)
go
set disable_ri_check on
go
set statement_cache off
go
insert t2 values(1,5)
go
!! succeeds since query plan for 1st attempt is ignored
(due to disabling my session's statement cache) so
2nd query is compiled from scratch with the new
disable_ri_check setting
==================
insert t2 values (1,5)
go
set disable_ri_check on
go
set ansinull on -- or any other setting that forces
go -- a recompilation
insert t2 values(1,5)
go
!! succeeds since the 'set ansinull on' forces a
recompile of the query plan
==================
While a change in a setting like 'ansinull' forces a recompilation of the query plan, it appears that changing the value of disable_ri_check does *NOT* force a recompilation. Net result is that my 2nd insert attempt fails if it's forced to re-use the query plan of the 1st insert (when disable_ri_check=off).
Your 2nd example worked because you got to use a new query plan (due to having dropped/recreated the tables between tests). Do you also get the failure if you run your test the same way I did, ie, insert/set/insert (w/ statement cache on)?
Assuming you also get the error (in SP122), this looks like a bug/CR: changing a session's disable_ri_check value should force a recompilation of cached query plans (akin to what happens when changing a session's ansinull setting).