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 7717385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:53:05+00:00 2026-06-01T02:53:05+00:00

I was wondering if there was any performance difference between the two approaches below.

  • 0

I was wondering if there was any performance difference between the two approaches below.
Basically, the issue is we allow spaces and dashes in an id but certain legacy applications are unable to use these so they are stripped out.
As far as I can see the neatest way to do this is either in a trigger or as a calulated column.
The SQL is shown below (cleaned up and anonymized so apologies if an error crept in)
So far on our test servers, there doesn’t appear to be any difference between the two methods, does anyone else have any input?

[Database SQL Server 2008]
[Lookup table 20000000 rows and growing]

Option 1 – Create trigger

CREATE TRIGGER triMem_Lkup on Mem_Lkup
INSTEAD OF INSERT
AS
BEGIN
  INSERT INTO Mem_lkup
       SELECT ex_id, contact_gid, id_type_code, date_time_created,
              (replace(replace([ex_id],' ',''),'-','')) as ex_id_calc
       FROM inserted
END
GO

Versus
Option 2 – use a calculated column

CREATE TABLE [dbo].[Mem_lkup](
    [mem_lkup_sid] [int] IDENTITY(1,1) NOT NULL,
    [ex_id] [varchar](18) NOT NULL,
    [contact_gid] [int] NOT NULL,
    [id_type_code] [char] (1) NOT NULL,
    [date_time_created] [datetime] NOT NULL,
    [ex_id_calc]  AS CAST( replace( replace([ex_id],' ','')  ,'-','')  AS varchar(18)) PERSISTED

    CONSTRAINT [PK_Mem_Lkup] PRIMARY KEY NONCLUSTERED 
(
    [mem_lkup_sid] ASC
)

Which one is best?

  • 1 1 Answer
  • 0 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-06-01T02:53:07+00:00Added an answer on June 1, 2026 at 2:53 am

    Computed columns will be best.

    The INSTEAD OF trigger will create the whole pseudo inserted table in tempdb first.

    Plan

    For the trigger version with your CREATE TABLE statement (non clustered PK on a heap)

    SET STATISTICS IO ON;
    
    INSERT INTO [_test].[dbo].[Mem_lkup]
               ([ex_id]
               ,[contact_gid]
               ,[id_type_code]
               ,[date_time_created])
    SELECT type AS  [ex_id]
          ,1 [contact_gid]
          ,'A' [id_type_code]
          ,getdate() [date_time_created]
      FROM master..spt_values
    

    Gives me

    Table 'Worktable'. Scan count 0, logical reads 5076
    Table 'spt_values'. Scan count 1, logical reads 15
    
    Table 'Mem_lkup'. Scan count 0, logical reads 7549
    Table 'Worktable'. Scan count 1, logical reads 15
    

    Whereas the calculated column version is similar but avoids the worktable reads.

    Table 'Mem_lkup'. Scan count 0, logical reads 7555
    Table 'spt_values'. Scan count 1, logical reads 15
    

    Is there any reason you are persisting this value at all though? (as opposed to having a non persisted computed column)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering is there any difference in terms of performance between the two
I was wondering if there is any difference in performance/memory use between movieclip symbol
I was wondering if there is any difference in performance (or any other important
I was wondering if there is any difference in performance when you compare/contrast A)
I am wondering if there is any difference in runtime between a generic container
I was wondering if there were any performance implications between using TPL TaskFactory.FromAsync and
I am wondering if there is any performance differences between String s = someObject.toString();
I was wondering if there are any differences - mostly performance wise - between
I was wondering if there are any performance differences when using simple queries as:
I was wondering if there is any concurrency (now or future), or performance benefit

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.