I have hundreds of procedures that got installed to a database with quoted identifiers set to off and I need them set on. I'm able to view the list of these procedures using the following
SELECT name = OBJECT_NAME([object_id]), uses_quoted_identifier
FROM sys.sql_modules
WHERE uses_quoted_identifier <> 1 AND OBJECT_NAME([object_id]) LIKE '%%'
ORDER BY OBJECT_NAME([object_id])
Now I know I cannot do an update directly to sys.sql_modules to set the uses_quoted_identifier. I could manually open all the scripts and reinstall but that's time consuming. I could also probably make a batch file to run that same process but that's still time consuming albeit slightly less.
Is there an easier way I can go about updating these?
UPDATE While doing some more research I came across this post which made me realize, the quoted identifier stuff is all my own doing because I had a batch command already that was installing procedures from a specific directory: SET QUOTED IDENTIFIER should be ON when inserting a record
I realized using this article I can add -I to my sqlcmd to enable Quoted Identifiers: https://sqlsailor.com/2014/11/14/sqlcmdoptions/
I'll leave this question open for now incase any one has a trick to programmatically update the Quoted Identifiers on procedures but this should fix my issue for now.
I had a similar issue not too long ago where I had to find and fix incorrect
quoted identifier
settings along with numerous other issues in hundreds of procedures in several databases. Part of the task was to find and remove any explicit set options such asquoted_identifer
,ansi_nulls
transaction isolation level
and many other common issues including removing usage of quotes"
in many legacy procedures that used dynamic sql and hadquoted_identifer
set to off.This is the bones of my solution which you might like to tinker with to your requirements.
I get the sql text of all the relevant objects - procs, functions etc into a temp table then do various string replaces to fix specific issues. I then iterate through and use dynamic sql to just recreate the objects, which naturally get the correct default
set options
. Any that fail are indicated in the table and I then deal with manually.