i have the following 3 related tables
Schools           Departments          Classes
---------------   ------------------   -----------------
ID                ID                   ID
School_Name       ID_Schools           ID_Departments
                  Department_Name      Class_Name
and a little sample about what they contain ( I'll draw the best i can )
---- Schools ---
ID   School_Name
----------------
 1   School_1  <----------------------\
 2   School_2                         |
 n   ........                         |
                                      |
---- Departments ----------------     |
ID   ID_Schools   Department_Name     |
---------------------------------     |
 1            1   Dept_1  <-----------/ -->--\
 2            1   Dept_2  <-----------/ -->--|------\
 3            2   Dept_1                     |      |
 n           ..   ......                     |      |
                                             |      |
---- Classes -------------------             |      |
ID   ID_Departments   Class_Name             |      |
--------------------------------             |      |
 1                1   Class_1  <-------------/      |
 2                1   Class_2  <-------------/      |
 3                1   Class_3  <-------------/      |
 4                2   Class_1  <--------------------/
 n               ..   .......
all IDs are auto-increment
i'm looking for a way to copy 'School_1' hierarchy. and the problem is how can i maintain relationship between new rows ?
for example to copy 'School_1' hierarchy, I'll insert a new raw into Schools table, which eventually will produce a new ID ( 5 for example ).
---- Schools ---
ID   School_Name
----------------
 5   School_1
departments 'Dept_1' and 'Dept_2' that belong to 'School_1' will get new IDs
---- Departments ----------------
ID   ID_Schools   Department_Name
---------------------------------
16            5   Dept_1
17            5   Dept_2
and classes will also get new IDs
---- Classes -------------------
ID   ID_Departments   Class_Name
--------------------------------
56               16   Class_1
57               16   Class_2
58               16   Class_3
59               17   Class_1
how can i achieve this a simple and smart way ?
 
     
     
     
    