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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:16:20+00:00 2026-06-01T15:16:20+00:00

I have to insert the values in the table named First, but before inserting

  • 0

I have to insert the values in the table named “First”, but before inserting the value i have to check whether the row exists there or not with a following Registered “name”. If the row value is present there, then i have to remove that row and insert the values present in that row to different table named “second”. Then, i have to insert the my present value to the “first” table.

I am Using SQL server 2005

  • 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-01T15:16:21+00:00Added an answer on June 1, 2026 at 3:16 pm

    This seems to me as you are trying to create history table. It is usually done in trigger because it covers all possible scenarios.

    Here is a stored procedure you might call from java to insert or update First:

    create proc ReplaceName (@Name varchar(100), @Value1 varchar(100), @Value2 varchar(100))
    as
       set nocount on
    -- try to update Name with new values
       update [First]
          set Value1 = @Value1,
              Value2 = @Value2
        where Name = @Name
    -- If it does not exist
       if @@rowcount = 0
       begin
    -- Insert new row
          insert into [First] (Name, Value1, Value2)
               values (@Name, @Value1, @Value2)
       end
    

    And this is a trigger that saves old copies into second:

    create trigger HistoryFirst on [First]
    after insert, update
    as
       set nocount on
    
       insert into [Second] (Name, Value1, Value2)
            select Name, Value1, Value2
              from Deleted
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-row insert that looks something like: insert into table VALUES (1,
I have the following query in VBA: DoCmd.RunSQL INSERT INTO table (value) VALUES ('example')
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where
I have the following query: INSERT INTO table (a, b, c) VALUES (NOW(), NOW()
I have one multi-row INSERT statement (300 or so sets of values) that I
I have very slow insert to my InnoDb table (2 500 000 notes). But
I have the following script that I want to insert into a table, but
I have the following code: <? $query =$db->prepare(INSERT INTO a_table (id, a_field) VALUES ('',
Hi I have this method below which should insert values into my database. However

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.