# Database re-structuring

**URL:** <https://www.ruby-forum.com/t/database-re-structuring/58233>\
**Category:** Ruby\
**Created:** [April 19, 2006, 9:21pm UTC](https://www.ruby-forum.com/t/database-re-structuring/58233 "2006-04-19T21:21:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [April 19, 2006, 9:21pm UTC](https://www.ruby-forum.com/t/database-re-structuring/58233/1 "2006-04-19T21:21:20Z")

</div>

Hi everyone, I am looking for some suggestions here.

I’ve got an older mysql database, one table, dumped into a SQL file.

I want to use this data in my new database, only this time I want the  
data to go into multiple tables instead of one big table.

I was thinking of writing a script to parse the SQL file and based on  
each entry, put the information where it needs to go. I also thought of  
feeding the SQL file into my new database, and write a script that went  
thought each row in the data of old table (with a SELECT \*) and figured  
out where to put it in the new tables.

Is this an insane way to do things? I have a feeling I am doing a lot  
more work than necessary. Does anyone have any suggestions?

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [April 19, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/database-re-structuring/58233/2 "2006-04-19T22:17:10Z")

</div>

On 4/19/06, Dick D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is this an insane way to do things? I have a feeling I am doing a lot  
> more work than necessary. Does anyone have any suggestions?

If the dumped SQL is fairly simple and regular, I’d just write a  
script to parse it and add things to the right tables. I think it is  
overkill to import it into a new table just so you can later select  
and re-insert it.

Ryan

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [April 20, 2006, 5:26am UTC](https://www.ruby-forum.com/t/database-re-structuring/58233/3 "2006-04-20T05:26:49Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

zdennis wrote:

> > > script to parse it and add things to the right tables. I think it is  
> > > overkill to import it into a new table just so you can later select  
> > > and re-insert it.
> 
> Depending on how big the table was, you could do this all from within a  
> mysql batch script, by using “insert … select” statements.

Actually it has nothing to do with big… it just has to do with writing  
a mysql batch script…

Zach  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.1 (GNU/Linux)  
Comment: Using GnuPG with Thunderbird - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iD8DBQFERv7KMyx0fW1d8G0RAuihAJ9BZQ+thrHF7ePEOboIrxiJum9mxgCfZPAP  
QJ/10EUzkWvbmI676bp7IUI=  
=ETBE  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [April 20, 2006, 5:20am UTC](https://www.ruby-forum.com/t/database-re-structuring/58233/4 "2006-04-20T05:20:46Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Ryan L. wrote:

> 

Depending on how big the table was, you could do this all from within a  
mysql batch script, by using “insert … select” statements.

Zach  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.1 (GNU/Linux)  
Comment: Using GnuPG with Thunderbird - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iD8DBQFERv3pMyx0fW1d8G0RAmNbAJwOaBKouHWL0xDJh5WjmG0uKnj1IgCfb+RM  
B5NCP6dClBplgDzh+LIQhW4=  
=L1Pr  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [April 26, 2006, 12:39am UTC](https://www.ruby-forum.com/t/database-re-structuring/58233/5 "2006-04-26T00:39:13Z")

</div>

Robert K. wrote:

> Since mysql 5 you can also write a stored procedure that will read the  
> table with a cursor and distribute the data to several tables.  
> Disclaimer: haven’t used mysql stored procedures yet so I don’t know  
> how mature they are.
> 
> Kind regards
> 
> robert

Thanks for the suggestion Robert (and everyone else). I will have a  
look at these “stored procedures” on [mysql.org](http://mysql.org)

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [April 20, 2006, 11:25am UTC](https://www.ruby-forum.com/t/database-re-structuring/58233/6 "2006-04-20T11:25:31Z")

</div>

2006/4/19, Dick D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi everyone, I am looking for some suggestions here.
> 
> I’ve got an older mysql database, one table, dumped into a SQL file.
> 
> I want to use this data in my new database, only this time I want the  
> data to go into multiple tables instead of one big table.

> Is this an insane way to do things? I have a feeling I am doing a lot  
> more work than necessary. Does anyone have any suggestions?

Since mysql 5 you can also write a stored procedure that will read the  
table with a cursor and distribute the data to several tables.  
Disclaimer: haven’t used mysql stored procedures yet so I don’t know  
how mature they are.

Kind regards

robert
