tags:

views:

193

answers:

7

I am busy developing 2 web based systems with MySql databases and the amount of tables/views/stored routines is really becoming a lot and it is more and more challenging to handle the complexity.

Now in programming languages we have namespacing e.g. Java packages, C++ namespaces to partition the software, grouping it together to make things more understandable. Databases on the other hand have more of a flat structure (MySql at least) e.g. tables and stored procedures are on the same level. So one have to be more creative, creating naming conventions, perhaps use more than one database or using tools to visualize things.

What methods do you use to ease the pain? To be effective while developing your databases? To not get lost in a sea of tables and fields and stored procs?

Feel free to mention tools you use also, but try to restrict it to open source and preferably Linux solutions if thats OK.

b.t.w How many tables would a database have to be considered large in terms of design?

+1  A: 

Definitely, definitely use naming conventions. MySQL database design is one of the last places that I use hungarian notation, but I start all my tables with "tbl", all my views with "v", etc.

Additionally, I build multiple database diagrams in MySQL Workbench, generally at least one diagram per domain aggregate, that help me visualize the "modules" in the architecture.

This is one area where a product like Sql Server has big advantages, as database objects can belong to multiple schemas inside a database, much like namespaces in programming.

womp
+1  A: 

Well... there is no real solution in MySQL. With some databases (PostgreSQL for example) you do have namespaces and you can do this.

You could ofcourse work around it by using multiple databases to emulate namespaces but that might give a lot of problems.

Personally I would simply name everything in such a way that your management tool can distinguish it (like phpMyAdmin automatically uses underscores to group databases).

WoLpH
phpMyAdmin that recognises underscores is nice. I guess that if one's naming conventions is right one should be able to generate code e.g. data access objects that map the db structures to namespaces, classes and methods. The key would be consistency.
Hannes de Jager
I'd vote against creating multiple databases just to "organize" your tables. I think that would create more problems than it was worth. Like, will your DBMS let you join across databases? I don't think most will, so right there you've introduced a huge problem.
Jay
@Jay: in the case of MySQL you can join across databases, that is the only reason I gave it as an option. But I agree with you that it's far from recommended and I really don't have a clue how the query planner handles that.
WoLpH
@WoLpH: You can join across databases in MySQL? I didn't know that. I'm not sure that I'll ever use it, but it's cool to know.
Jay
+3  A: 

The only solution I've found that is generally applicable is to develop a series of prefixes and apply them to tables (for instance, tables relating primarily to Human Resources would all start hr_). I generally carry the prefixes across to other "objects" in the application (forms, reports, views, stored procedures).

This solution is far from perfect and is something of a hack but it does bring a modicum of order to the system.

Larry Lustig
+1  A: 

In some databases you have schemas you can use, but I think not in mySQL. Naming conventions to keep related tables together are your best bet. One thing I try especially to do is be very consistent in naming fields in different tables exactly the same thing. If my user table calls for a user_id, then I don't want to see it as person_id, userid, User, etc in different related tables. Also when using the same type of field from table to table use the same datatype (and size if it is string data). Then you won't be continually having to convert data to do joins.

As far as how many tables you need to be a large database, that is more a function of how many records in the tables not the number of tables. Many small databases have hundreds of tables. I would almost never worry about the number of tables unless I saw someone creating tables something like Financials2009, Financials2010, etc.

HLGEM
you can do select * from dbname.tablename in MySQL.
Seun Osewa
Ditto on using consistent field names. I'm working on a database these days where not only is there a lot of unnormalized redundant data, but when they do copy the fields, they give them different names! So in one table we have "basecost" and in another we have "cost" and in another we have "amount". Another field is "delivereddate" here and "datedelivered" over there and "deliverydate" in another table. And those you could at least guess. Who would know that "prodid" and "style" are the same thing? Etc. Argggh!!
Jay
+2  A: 

Oracle E-Business Suite has over 25,000 tables and around 33,000 views. I would say that was a large schema.

APC
+1  A: 

A solution that worked well for me on one project was that we divided the database into chunks, then we drew a big ERD (we used Corel, actually, though there are many fancier tools available), we color-coded the boxes for each table to show what chunk each was in, then we printed it out on a large-format printer so it was like 5 feet tall and 10 feet wide, and we hung it on the wall of my assistant's office. Not a high-tech solution, but it was incredibly practical.

We were also meticulous about consistent naming, to echo HLGEM's answer.

In retrospect, a naming convention that would have prefixed each table name with a "chunk name" would probably have been a good idea, but we fared quite well without it.

As to how big is big? I don't know, a highly subjective question. I generally think that a database is big when I can't picture the whole thing in my head at one time. In practical terms, I guess when you pass a few dozen tables. Number of records is pretty much irrelevant: A database with two tables that have a billion records each would be easy to comprehend; a database with a 1000 tables that have ten records each would be hard to comprehend.

Jay
A: 

Databases on the other hand have more of a flat structure (MySql at least)

...but you can have multiple databases running on the same mysql instance, e.g.

SELECT *
FROM common.address adr
purchasing.orders pod
WHERE pod.cust_id=adr.cust_id

(NB try to avoid the mysql 'USE dbname'). It's a good idea to standardize your alias names in queries.

How many tables would a database have to be considered large in terms of design?

I don't think that there's a standard metric. I'd probably start getting confused around 50. One of the Oracle DBs I look after has 1567 (yes, it is normalized (sort of))

symcbean