# How to model large SqlServer database

**URL:** <https://www.ruby-forum.com/t/how-to-model-large-sqlserver-database/113179>\
**Category:** Rails\
**Created:** [August 28, 2007, 12:55pm UTC](https://www.ruby-forum.com/t/how-to-model-large-sqlserver-database/113179 "2007-08-28T12:55:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![clive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@clive](https://www.ruby-forum.com/u/clive)\
**Post date:** [August 28, 2007, 12:55pm UTC](https://www.ruby-forum.com/t/how-to-model-large-sqlserver-database/113179/1 "2007-08-28T12:55:58Z")

</div>

I have been contracted to work on an intranet using Rails to generate  
content. Part of this work is to model and generate queries on the  
legacy SQL Server 2000 database that contains about 80 tables. The  
database itself is in 3NF form and follows an in-house naming  
convention that I cannot change.

My question is this: would I need to model all the tables within this  
database to be able to create the queries that I need under Rails? Or  
would it be better to create stored procedures (not the Rails way)  
within the database, and model a/some view(s) from the database?

I would appreciate any thoughts and/or help.

Clive

---

<div class="post-metadata">

**Author:** ![clive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@clive](https://www.ruby-forum.com/u/clive)\
**Post date:** [August 28, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/how-to-model-large-sqlserver-database/113179/2 "2007-08-28T17:12:55Z")

</div>

take a look to dr nic magic models:  
[http://magicmodels.rubyforge.org/dr\_nic\_magic\_models/](http://magicmodels.rubyforge.org/dr_nic_magic_models/)

models for your tables are ‘generated’ on the fly, without write a  
single line (i don’t know about performance side effects).

Raffa

---

<div class="post-metadata">

**Author:** ![clive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@clive](https://www.ruby-forum.com/u/clive)\
**Post date:** [August 28, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/how-to-model-large-sqlserver-database/113179/3 "2007-08-28T20:28:23Z")

</div>

Thanks for the link - I used the modules there, but i still have an  
issue with registering the primary keys and the database names, for some  
reason the set\_table\_name and set\_primary\_key calls are being ignored on  
the tables that I am using to test, magic models didn’t seem to pick up  
the primary keys or the foreign ones - looks like I will need to look  
harder in the documentation.

Again thanks for the link

Clive

---

<div class="post-metadata">

**Author:** ![clive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@clive](https://www.ruby-forum.com/u/clive)\
**Post date:** [August 29, 2007, 1:30pm UTC](https://www.ruby-forum.com/t/how-to-model-large-sqlserver-database/113179/4 "2007-08-29T13:30:10Z")

</div>

Thanks for the response - looks like I am going to have to bite the  
bullet and get on with it. From a Rails perspective, these databases are  
a mess, in fact from a SQL Server perspective they are a mess and the  
company knows it, what they won’t do is use some resource to clean them  
up.

> From some initial testing, the framework seems to be ignoring the  
> set\_primary\_key setting that I have provided for the test table, but  
> maybe I have set the query up wrong or something - will go back and  
> check.

Best get the waders on.

Clive

---

<div class="post-metadata">

**Author:** ![clive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@clive](https://www.ruby-forum.com/u/clive)\
**Post date:** [August 29, 2007, 6:37am UTC](https://www.ruby-forum.com/t/how-to-model-large-sqlserver-database/113179/5 "2007-08-29T06:37:21Z")

</div>

I would just create models for each table (script/generate model  
table\_name), then get real familiar with ‘set\_table\_name’, and  
‘set\_primary\_key’. If they are using compound primary keys, then  
you’ll need Dr Nic’s ‘CompoundPrimaryKey’ gem.

I’d also recommend creating the associations manually and not using  
the ‘magic models’ plugin.

I’ve done it with our in-house SQL Server db’s and it works fine…

Good Luck,

Rich C.
