...

View Full Version : Help in designing a Mysql table



jnrntr
07-13-2011, 10:56 PM
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.

Old Pedant
07-13-2011, 11:35 PM
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.



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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum