# Multiple "identical" tables

**URL:** <https://www.ruby-forum.com/t/multiple-identical-tables/182940>\
**Category:** Rails\
**Created:** [February 5, 2010, 1:43am UTC](https://www.ruby-forum.com/t/multiple-identical-tables/182940 "2010-02-05T01:43:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 5, 2010, 1:43am UTC](https://www.ruby-forum.com/t/multiple-identical-tables/182940/1 "2010-02-05T01:43:00Z")

</div>

Hi, there.  
I was wondering if it’s possible to have one controller and view that  
has multiple tables. Let say there are 10 schools. Each school has a  
table to stores students’ info. So one Student controller with 10  
tables. Is it possible or any workaround?  
Thanks in advances.

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 5, 2010, 3:10am UTC](https://www.ruby-forum.com/t/multiple-identical-tables/182940/2 "2010-02-05T03:10:35Z")

</div>

Ichiro S. wrote:

> Hi, there.  
> I was wondering if it’s possible to have one controller and view that  
> has multiple tables. Let say there are 10 schools. Each school has a  
> table to stores students’ info. So one Student controller with 10  
> tables. Is it possible or any workaround?

That’s a terrible setup. You should never have multiple identical  
tables – instead, all you need is one table for all students.

> Thanks in advances.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 5, 2010, 6:21pm UTC](https://www.ruby-forum.com/t/multiple-identical-tables/182940/3 "2010-02-05T18:21:49Z")

</div>

Marnen Laibow-Koser wrote:

> Ichiro S. wrote:
> 
> > Hi, there.  
> > I was wondering if it’s possible to have one controller and view that  
> > has multiple tables. Let say there are 10 schools. Each school has a  
> > table to stores students’ info. So one Student controller with 10  
> > tables. Is it possible or any workaround?
> 
> That’s a terrible setup. You should never have multiple identical  
> tables – instead, all you need is one table for all students.
> 
> > Thanks in advances.
> 
> Best,  
> –Â  
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

Thanks Maren.  
When there are 30+ schools and each has 100k+ students, it’ll be a very  
large table. That’s why I was thinking about breaking it into some  
smaller tables.

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 5, 2010, 8:56pm UTC](https://www.ruby-forum.com/t/multiple-identical-tables/182940/4 "2010-02-05T20:56:17Z")

</div>

Andreas S. wrote:

> Ichiro S. wrote:
> 
> > That’s why I was thinking about breaking it into some  
> > smaller tables.
> 
> Don’t. A few 100k or million rows are nothing for a database. As long as  
> you set up an index for the school\_id, splitting the students in  
> multiple tables has absolutely no advantage.

Right. If you _must_ break the table (which you probably won’t even  
need to do), then use your DB’s sharding features (such as MySQL’s MERGE  
tables) so that it still functions like one huge table.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 6, 2010, 5:21am UTC](https://www.ruby-forum.com/t/multiple-identical-tables/182940/5 "2010-02-06T05:21:02Z")

</div>

I second everybody else here. Add an identifier for the school in your  
table and you’ll be happier than with the setup you were going to use.

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 5, 2010, 6:39pm UTC](https://www.ruby-forum.com/t/multiple-identical-tables/182940/6 "2010-02-05T18:39:29Z")

</div>

Ichiro S. wrote:

> That’s why I was thinking about breaking it into some  
> smaller tables.

Don’t. A few 100k or million rows are nothing for a database. As long as  
you set up an index for the school\_id, splitting the students in  
multiple tables has absolutely no advantage.
