sql server - Is there any way to make this UDF deterministic? -


I agree that this is not just determinative because DB_NAME () is not deterministic? If DB_NAME () is not deterministic, then why is not it deterministic?

  Optional function [TheSchema]. [Udf_IS_PRODUCTION] returns the return bit as SCHEMABINDING as DB_NAME () = 'PRODUCTION' then convert (bit, 1) ELSE convert (bit, 0) END END  
< P> Update: This version works, determinists, allows the use of the same code in any database and removes the hardcoding of the database name (which is about the name of the database coding Other automatic systems also allow health exceptions to be removed)

  Optional function [TheSchema]. [Udf_IS_PRODUCTION] (Shortcut with SCHEMABINDING as the restart) (SELECT IS_PRODUCTION from SELECT_IN_PRODUCTION) END  

FYI This is the code snippet in my system Health self -Reporting system that I use to monitor potential problems.

  SELECT 'Non-deterministic scalar UDF' AS problem, QUOT ENAME (ROUTINE_SCHEMA) + '.' + As QUOTENAME (ROUTINE_NAME) from INFORMATION_SCHEMA.ROUTINES (NOLOCK) WHERE IS_DETERMINISTIC = 'no' and ROUTINE_TYPE = 'function' and DATA_TYPE & lt; & Gt; ROUTINE_SCHEMA 'Table' command, ROUTINE_NAME  

Sure, I can think in a way Make it determinable Deploy this function on your production database:

  Optional function [TheSchema]. [Udf_IS_PRODUCTION] () Bit Returns Convert (bit, 1) END  

and deploy it to your test database:

  Optional function [TheSchema] . [Udf_IS_PRODUCTION] Bit / code with SCHEMABINDING (bit, 0) END as a bit return convert () bit / code> 

This may look silly but the IMO database name can be compared to the return value of some UDF " Strictly coded "should not be.

Better yet, just enter this information somewhere in a configuration table.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -