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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:25:58+00:00 2026-06-12T22:25:58+00:00

I have 2 simple tables +——|———|———-+ + ID | Value | Test + +——|———|———-+

  • 0

I have 2 simple tables

+------|---------|----------+
+  ID  |  Value  |   Test   +
+------|---------|----------+
+  3   |   Test  |   12345  +
+  4   |  MyVal  |   56789  +
+  5   |  Another|   101010 +
+------|---------|----------+



+------|---------|----------+
+  ID  |  Value  |   Test   +
+------|---------|----------+
+  3   |   Test  |   12345  +
+  7   |  MyVal12|   56789  +
+  5   |  Another|   101010 +
+------|---------|----------+

The ID from both tables are primary keys.

In my stored procedure, I create a temporary table like this:

CREATE TABLE #tempTable(
        ID int NOT NULL PRIMARY KEY NONCLUSTERED,
        FIELD VARCHAR(255))

and the part of my procedure stored with try-catch block:

BEGIN TRY
INSERT INTO #tempTable(ID, FIELD)
EXEC sp_executesql @myCustomSql, @paramList, @param1, @param2 ...
END TRY

BEGIN CATCH
      // what to put here ?
END CATCH

I want to add rows to my temporary table (you’ll see the duplicates for ID = 3 and 5) and I want to continue adding. Finally I want to have the following content for table:

+------|---------+
+  ID  |  FIELD  +
+------|---------+
+  3   |   Test  +
+  4   |  MyVal  +
+  5   |  Another+ 
+  7   |  MyVal12+
+------|---------+

I gave here a simplified example, in my database I have over one hundred thousand rows and many columns.

Thanks

  • 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-12T22:25:59+00:00Added an answer on June 12, 2026 at 10:25 pm

    To ignore (with a warning) attempts to insert duplicate keys rather than raising an error and having the whole statement fail you can use the IGNORE_DUP_KEY option.

    CREATE TABLE #tempTable
      (
         ID    INT NOT NULL PRIMARY KEY NONCLUSTERED WITH (IGNORE_DUP_KEY = ON),
         FIELD VARCHAR(255)
      ) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple query that loads data from two tables into GUI. I'm saving
all! I have the following problem: I have 2 simple tables. The first one,
I have a simple parent/child tables. Contract is the parent table. Each contract can
I have a simple data model of two tables, email and recipients, email can
I have a relatively simple subset of tables in my database for tracking something
I have a simple database with multiple tables. I can't figure out how to
I have a simple ADO.NET Entity Framework 4.0 model (edmx) which defines database tables
I have a relatively simple query joining two tables. The Where criteria can be
I have created a simple view consisting of 3 tables in SQL. By right
I have a very simple database table that joins two other tables in a

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.