Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help in designing a Mysql table

    I have two tables: t1 and t2. t1 is the parent table, and t2 is the child.

    t2 has:

    title
    http
    recordno
    name
    etc..

    and there are around 500 records already in it.

    I want to create a parent table t1 which will have a fields

    id
    title
    http
    recordno

    id needs to auto increment for all the 500 rows in t2, and the remaining fields title, http and recordno should get the values from t2. So parent table t1 should be updated with 500 rows of t2 and in future if we insert new values in t2 these should also be updated in t1.

    I might have another child tables like t2 and i want t1 as a index for all these table with an unique id and t2 has around 80 fields while t1 will only have 4 unique fields.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Code:
    CREATE TABLE t1 (
        id INT AUTO_INCREMENT PRIMARY KEY,
        title VARCHAR(xxx),
        http VARCHAR(xxx),
        recordno INT );
    WHere the data types for all except id should match those of the existing table.

    Code:
    INSERT INTO t1 (id, title, http, recordid )
    SELECT NULL, title, http, recordid FROM t2;
    Done.

    Now. How do you know *WHICH* records in t1 match up with which records in t2??????

    Is it based on recordid? Or what?

    I'm not sure this is the best plan going forward. But you asked.


  •  

    Posting Permissions

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