I want to copy data from one table to ....

  • Dear

    I want to copy data from one table to another but it same data available then it should not be copied that rows.

    I have 2 databases with named 'today' and 'freeads' both contains table named with 'blogs'. and contains some same rows of data.

    now. i want that I want to copy data from blogs table of freeads to blogs table of today.

    I dont have primary key in any table.

    but it should copy again same records.

    I tried lot of time using import data but it copies same data as well.

    waiting for reply.

    regards,

    ASIF

  • If there is no primary key in either table, how can you determine whether two records are "the same". Do you have to compare all of the columns one by one?

    Are you able to create a SELECT statement that identifies the records you want to copy? If so, just use

    INSERT INTO DestinationTable(Field1, Field2, etc)

    SELECT Field1, Field2 etc

    FROM SourceTable

    WHERE ... your conditions here

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • I'm with Phil.

    If it's about comparing all the columns, you can do something along the lines of...

    --data

    declare @t table (a int, b int, c int)

    insert @t

              select 1, 1, 1

    union all select 1, 1, 2

    union all select 1, 1, 3

    union all select 1, 2, 1

    union all select 1, 2, 2

    union all select 1, 2, 3

    declare @U table (a int, b int, c int)

    insert @U

              select 1, 1, 1

    union all select 1, 1, 2

    union all select 2, 2, 2

    union all select 2, 2, 3

    --calculation

    insert @t

    select * from @U u

    where not exists (select * from @t where a = u.a and b = u.b and c = u.c)

    select * from @t

    /*results

    a           b           c          

    ----------- ----------- -----------

    1           1           1

    1           1           2

    1           1           3

    1           2           1

    1           2           2

    1           2           3

    2           2           2

    2           2           3

    */

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • If you often need to join on a lot of columns you may find that an indexed calculated column defined as checksum(*) is more convenient than an index on all join columns. It's also smaller - therefore as well as always staying within size limits, it's presumably more efficient. I haven't tested this though. Maybe someone else has?

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

  • How about setting a trigger on the blogs table of "freeads" to insert into table in "today"?!?!







    **ASCII stupid question, get a stupid ANSI !!!**

Viewing 5 posts - 1 through 4 (of 4 total)

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