SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Copy entire parent/child relationship

    I have a table containing rows with parent/child relationships, like this:

    Code:
    id title        parent_id
    1  Home         NULL
    2  Products     NULL
    3  Scooter      2
    4  Tricycle     2
    5  About us     NULL
    6  Services     NULL
    12 Quad bike    2
    20 FAQs         5
    I want to make a copy of this data and preserve the relationships in the copy (so that the duplicated Quad bike page's parent_id would reflect the new id assigned to the duplicated Products page). I'm using SQL Server 2005. Is there a quick way of doing this? There are about 2500 rows of data which I'd rather not have to sort through manually

    Any input would be much appreciated.
    Sam Hastings

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by SJH View Post
    I want to make a copy of this data and preserve the relationships in the copy
    where?

    i mean, in the same table, or in the same database, or where?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to be unclear. The data needs to be copied into the same table. Perhaps I could have been more sensible and put an important additional column in my example table structure country_code which is the only field that will change between the original data and the duplicated data.

    The need for replication is because we're introducing a US version of one of our sites and the content for UK/US versions will be exactly the same to start with.

    I did actually do a bit more Googling since posting my question and I did find this thread, which I'll try out tomorrow morning at work.
    Sam Hastings

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    i did not investigate that article in any detail but if you have trouble adapting it to your table, post your attempt here and we'll work it out
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I managed to get it working using the example query given in the above article, so consider this problem solved
    Sam Hastings


Bookmarks

Posting Permissions

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