Copy Rows to Another Table

  • I have 2 tables that are identical. I wish to copy some records from one table to the other with the following script.

    INSERT INTO RH2007_EvyLive.dbo.RETAIL_SALES

    SELECT *

    FROM Jay.dbo.RETAIL_SALES

    WHERE CUST_NO='MACY01'

    When I execute it I get the message "(2810 row(s) affected)" and "Query executed successfully". When I query RH2007_EvyLive.dbo.RETAIL_SALES, the records are not there.

    Any help would be appreciated.

    Jay

    SQL Server 2008 R2 standard

  • Any triggers on the destination table?

  • I don't believe there is a trigger. How can I find out for sure?

  • Look?

  • I appreciate your time to help me with this challenge. Please be patient since I am a rookie. I have never intentially created a trigger since I honestly do not know it's purpose. Using SSMS there were no triggers under "Database Triggers".

  • Check this image to know where to find the triggers.

    Use the appropriate table.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks Luis. No triggers.

  • JayWinter (9/14/2012)


    I have 2 tables that are identical. I wish to copy some records from one table to the other with the following script.

    INSERT INTO RH2007_EvyLive.dbo.RETAIL_SALES

    SELECT *

    FROM Jay.dbo.RETAIL_SALES

    WHERE CUST_NO='MACY01'

    When I execute it I get the message "(2810 row(s) affected)" and "Query executed successfully". When I query RH2007_EvyLive.dbo.RETAIL_SALES, the records are not there.

    Any help would be appreciated.

    Jay

    SQL Server 2008 R2 standard

    I know this will sound like a stupid question but, as you said, you're new to SQL and I have to ask because of that.

    How do you know the rows weren't actually inserted? What code did you use to make that determination?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Good question Jeff.

    I let SSMS generate the code to print the TOP 1000 records. There are over 100 columns in the table so here is the code after removing most. I added the WHERE clause.

    /****** Script for SelectTopNRows command from SSMS ******/

    SELECT TOP 1000 [CUST_NO]

    ,[YR]

    ,[MO]

    ,[WK]

    ,[SEQ_ID]

    FROM [Evy_RH_Objects].[dbo].[RETAIL_SALES]

    WHERE [CUST_NO]='MACY01'

  • I just noticed I queried a different table. It worked. Thank you all.

  • I like the way Jeff determined to identify the issue 🙂

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply