Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1000677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:33:05+00:00 2026-05-16T07:33:05+00:00

Comparing two codes below,both do the same,but with slighty differences: ALTER procedure [dbo].[SP_USUARIOS_UPDATE] @usu_ds

  • 0

Comparing two codes below,both do the same,but with slighty differences:

ALTER procedure [dbo].[SP_USUARIOS_UPDATE]
    @usu_ds varchar(100),
    @usu_dt_lst_log datetime,
    @usu_ds_senha varchar(255),
    @usu_ds_email varchar(100)
    as
    begin
    declare @usu_ID int;
    create table #TempUser
    (
        UsuID int,
        Senha varchar(255),
        Email varchar(100)
    )
    select Usuarios.usu_ID as UsuID,Usuarios.usu_ds_senha as Senha, 
    Usuarios.usu_ds_email as Email into #TempUser from Usuarios where Usuarios.usu_ds = @usu_ds
    if(@usu_ds_senha is null)
    begin
    set @usu_ds_senha = (select #TempUser.Senha from #TempUser);
    end
    if(@usu_ds_email is null)
    begin
    set @usu_ds_email = (select #TempUser.Email from #TempUser);
    end
    set @usu_ID = (select #TempUser.UsuID from #TempUser);
    update Usuarios set usu_dt_lst_log = 
    @usu_dt_lst_log,usu_ds_senha = @usu_ds_senha,usu_ds_email = @usu_ds_email where usu_ID = @usu_ID
    end

AND

ALTER procedure [dbo].[SP_USUARIOS_UPDATE]
@usu_ds varchar(100),
@usu_dt_lst_log datetime,
@usu_ds_senha varchar(255),
@usu_ds_email varchar(100)
as
begin
declare @usu_ID int;
if(@usu_ds_senha is null)
begin
set @usu_ds_senha = (select Usuarios.usu_ds_senha from Usuarios where Usuarios.usu_ds = @usu_ds);
end
if(@usu_ds_email is null)
begin
set @usu_ds_email = (select Usuarios.usu_ds_email from Usuarios where Usuarios.usu_ds = @usu_ds);
end
set @usu_ID = (select Usuarios.UsuID from Usuarios where Usuarios.usu_ds = @usu_ds);
update Usuarios set usu_dt_lst_log = 
@usu_dt_lst_log,usu_ds_senha = @usu_ds_senha,usu_ds_email = @usu_ds_email where usu_ID = @usu_ID
end

Do you think the first is faster than second in performance,i mean,first code use temp table (#TempUser) to store 3 fields from the real table.Second code,select all fields from the real table one by one.

What code is best optimized?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:33:06+00:00Added an answer on May 16, 2026 at 7:33 am

    First — if it’s possible for your passed parameters to be null, you need to set defaults. For example:

    @usu_ds_email varchar(100) = null
    ...
    

    Otherwise, your null checks further down will never come into play — the procedure will just fail.

    Second — just run a direct update. It seems like you’re pushing a lot of data back and forth unnecessarily. E.g., you don’t need to create a temp table from the table you’re going to update, and then turn right around and update your table from the temp table you just created.

    ALTER procedure [dbo].[SP_USUARIOS_UPDATE]
    @usu_ds varchar(100),
    @usu_dt_lst_log datetime,
    @usu_ds_senha varchar(255) = null,
    @usu_ds_email varchar(100) = null
    as
    begin
    
        update Usuarios 
        set usu_dt_lst_log = @usu_dt_lst_log,
            usu_ds_senha = isnull(@usu_ds_senha, usu_ds_senha),
            usu_ds_email = isnull(@usu_ds_email, usu_ds_email)
        where usu_ID = @usu_ds
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am comparing two objects of the same type and returning the differences into
I am compiling the same project under two different compilers. The snippet below compiles
I am building an array based off comparing two other arrays. But when I
Possible duplicate : comparing-two-arrays I have two NSArray and I'd like to create a
Possible Duplicate: Comparing Two Arrays Using Perl I am trying to find elements that
I need to add custom validator for comparing two dates - start date and
I am having some trouble comparing two variables, hope someone could help. Basically what
I'm trying to follow the steps found here on comparing two arrays, and knowing
I am wondering about the use of == when comparing two generators For example:
Ok , so thanks to Claus Broch I made some progress with comparing two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.