SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    restructuring table, copying 1 col into a new col

    Hi,

    I am amending my table struture/relationships and I need to copy the data from an auto_increment col, to a new col which will be an fk to another table.

    what query should I use to copy from a col in one table to another col in the same table?

    bazz

  2. #2
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I got it.

    Code MySQL:
    UPDATE business_details 
    SET address_id = business_id

    But what if I do this...?

    I am working with a new table, a copy of address. if I set some fk's constraints in 'businesses' to relate to 'addresses' and then I change addresses to 'address', will the fk's update as well?

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    okay, that's 5 tables in all -- business_details, address, a copy of address, businesses, and addresses

    please take a moment and do a SHOW CREATE TABLE for each table, so that we can see what you're talking about
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry rudy, I forgot that only I am familiar with this. there were only two tables ~ 'business details' and 'address' and, I got sorted with

    Code MySQL:
    UPDATE business_details
    SET address_id = business_id

    after that I just had to amend the query in a few scripts and set up a new constraint.

    bazz


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
  •