Results 1 to 7 of 7

Thread: transfering data from one table to another table

  1. #1
    Join Date
    Oct 2006
    Posts
    9

    transfering data from one table to another table

    If we are transfering data from one table to another table say for ex transfering 1000 rows from one table to another table, how we can find whether all the rows are transfered.

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Anothe interview question? You should spend time to read some sql basic books. Anyway, you can query target table.

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    How are you transferring it? Did you use

    INSERT INTO tableB
    SELECT FROM tableA

    If it fails then you get an error, otherwise it succeeded. You can check the row count on tableB.

  4. #4
    Join Date
    Oct 2006
    Posts
    9
    No By triggers we transfer from one table to another. Is there any way to transfer the data from one table to another.

  5. #5
    Join Date
    Sep 2002
    Posts
    5,938
    You can use above mentioned statement, or use dts package.

  6. #6
    Join Date
    Aug 2007
    Posts
    3
    Maybe I don't fully understand your question...but get a count of the source table prior to data load, then get a count of the target table after the load, and compare. count1 = count2, then successful.

  7. #7
    Join Date
    Aug 2007
    Location
    Monrovia, Liberia
    Posts
    1

    Thumbs up To transfer data from one table1 to table2 by way trigger

    Nisha, i hope i understood your question of transfering data from one table to another.To answer your question, i will say YES.By way of trigger, it means that data will automatically be transferred or inserted in table2 as the result of a delete,update or insert from table2. In my code, u will see that only data inserted in table1 will be transferred or inserted in table2(row by row).Assuming that you have two tables(table1 and table2)
    and tb1id,tb2id as primary keys respectively for each table.

    Then the trigger will be:


    CREATE trigger trig1
    on table1
    for insert as

    DECLARE @tb1ID numeric(9), @count int

    SELECT @tb1ID=ins.@tb1ID,
    @count=count(*)
    FROM inserted ins WHERE ins.@tb1ID not in (select @tb2ID from table2)
    GROUP BY ins.@tb1ID
    if @count =1
    begin
    insert into table2(tb2id) Select tb1id FROM table1 WHERE tb1id=@tb1id
    end

    On the other hand, we can do a buck insert;that's
    insert into table1 select name_offield from table2
    without any where clause.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •