开发者

Database: A table for each language or one table with a language column

I am creating a book database in mysql. One book can have different languages. And there is going to be many thousand books. (And I am far from a pro in this field, only created small and simple databases before)

1) Is it fast enough to just create one table with a language column and create an index for it. 2) Or will it be significantly faster to create a table for each language.

My intuition (witch is not jet reliable in this field) tells me to go with the first option. I think it is more normalized to. It looks much cleaner and easier to extend to more languages. And it requires less programming. However, it is mainly the English language that are going to be used (It will also be the larges collection), and will it not take more time to access those books when the table is filled books written in other languages?

Speed is of some importance since it is going to be used on a website. But if there is no significant performanc开发者_StackOverflow中文版e difference I prefer to chose the easy way.

It will not be many different languages, 5 max 10, i guess.


Just only fetch the language you need from the table, which has all the languages you need.


To be honest (and DBAs may scream here) I would not consider performance before design, in other words I would try to create the schema as best I can without focusing solely on performance, you can always tweak it later. If one book can have many languages then maybe a BookLanguage table would help e.g.

book_id | lang
--------------
1       | es
1       | en
2       | de

So the book with id 1 is printed in Spanish and English, whereas book with id 2 is only available in German

Check out this link for some DB design best practises


Create a table for books, a table for languages, and a composite table that contains the primary key from the books table and the primary key from the languages table. That way, each book could potentially be printed in multiple languages. Composite tables are a clean way of doing this sort of thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜