sql server - Performance of stored proc when updating columns selectively based on parameters? -


I'm trying to figure out if it is T-SQL with relatively better performance (the SQL Server 2008). I need to create a stored procedure that updates a table. Prap accepts many parameters because there are columns in the table, and with the exception of the PK column, they all become zero by default. Looks like body this process:

  process create proc_repo_update @object_id bigint, @ varchar OBJECT_NAME (50) = null, @ object_type char (2) = null, @ Object_weight = integer zero, @ owner_id = integer zero - ... etc beginning object_repo OBJECT_NAME = IsNull (@object_name, OBJECT_NAME) set updates, object_type = IsNull (@object_type, object_type), object_weight = IsNull (@object_weight, object_weight), owner_id = IsNull ( @owner_id, owner_id) - ... etc where object_id = @object_id return @@ ROWCOUNT end  

so basically:

only one column Update provided its corresponding parameters , And was to leave the rest alone.

It works quite well, but as IsNull call value column will return the if parameter was zero, what SQL Server like this Will anyone optimize? There may be a demonstration spike on this application near the table where the table can be updated heavily (so there is no problem in the display, entry will be unusual). That's why I am trying to figure out what is the best way to do this. What is the status of the column expression like case when or something else? The table will be indexed to read well as Vazu. Is this the best way? At this point, I have to make the UPDATE expression in my option code (eg inline SQL) and execute it against the server. It will solve my doubts about performance, but if possible, I would like to leave it in a stored proc.

Hugo Cornelis See blog post little scroll down to discuss COALESCE vs ISNULL. If portability is the idea of ​​a future, see COALESCE.

However, from the Display perspective, take a look at Adam's performance-focused blog post ISNULL is fast.

Your choice ...

BTW, I have a bunch of SPs that are like your example and there is no display problem using ISNULL. (Being a bit lazy, I would like to write 6 versus 8 characters and I would like to be slightly dark with finger dyslexia, ISNULL is very easy to type :-))


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -