1
\$\begingroup\$

Base Info

  • Two tables: tData, tData2
  • Exactly the same columns
  • About 200,000 records
  • SQL Server 2008 R2

Logic

At first sight we need to insert tData rows into tData2. What else?

We need a renamed version of a column inside another (tData2) with the condition checking it won't be an existing item when it's renamed. Here's the code:

INSERT INTO [tData2]
(
 [Key],
 Info1,
 Info2
)
SELECT 
 REPLACE([Key],'_',' '),
 Info1,
 Info2
FROM
 [tData]
WHERE
 (REPLACE([Key],'_',' ') = [Key]) OR
 (REPLACE([Key],'_',' ') NOT IN (SELECT [Key] FROM [tData]))

The problem is it's really slow for me on a top-notch 64 bit system. It has taken more than an hour so far and it's still executing.

How to speed it up? Any alternatives? Any ideas?

Adam
5,2161 gold badge30 silver badges47 bronze badges
asked Jul 18, 2012 at 19:02
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I'm not a DBA/DBMS guru, so just some ideas:

answered Jul 18, 2012 at 20:59
\$\endgroup\$
3
  • \$\begingroup\$ Anyway this is a valuable comment, I liked it, Could you please give an example on the last part you mentioned ? \$\endgroup\$ Commented Jul 19, 2012 at 5:07
  • 1
    \$\begingroup\$ @Sypress: I'm sorry, I've tried to rewrite the query but I gave it up after a few tries. I haven't used so complex SQL queries recently. Please let me know how went the migration and what worked or not. \$\endgroup\$ Commented Jul 19, 2012 at 9:37
  • 1
    \$\begingroup\$ no problem friend, thanks again, your suggestions could be useful to me. \$\endgroup\$ Commented Jul 19, 2012 at 9:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.