为多语言网站设计数据库模式 [英] Designing database schema for a multi-language website

查看:227
本文介绍了为多语言网站设计数据库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

多语言数据库设计的最佳做法是什么?

我开发了多语言网站,我对它的设计数据库模式感兴趣。有一个表格文章

I develop multi-language website, and I'm interested about the designing database schema for it. Surpose, there's a table "Articles"

Articles (Id, AddedByUser, AddedDate, Title, Description, Body, ViewCount).

要实现多语言有两种方法。

To implement multi-languages there are two ways.

第一种方法是创建一个表

The first way is to create one table

Articles (Id, AddedByUser, AddedDate, TitleRU, TitleEN, DescriptionRU, DescriptionEN, BodyRU, BodyEN, ViewCount).

第二种方法是创建三个表

The second way is to create three tables

Articles (Id, AddedByUser, AddedDate, ViewCount). 
ArticlesLocalized(Id, ArticleId, Title, Description, Body, LanguageId)
Languages(Id, Name)

哪种方式是最好的?

推荐答案

多个表绝对是要走的路。这将使查询更容易(您将能够使用完全参数化的查询 - 例如... WHERE language =? - 而不必连接字符串 - ex 选择标题+ lang_code ),它将使添加新的语言更简单(如果适用),你会得到温暖的模糊感觉从正确的规范化数据(我可能是错误的,但我相信多列选项将违反1NF )。

Multiple tables is definitely the way to go. It will make queries easier (you'll be able to use fully parameterized queries — ex "… WHERE language=?" — instead of having to concatenate strings — ex "SELECT Title" + lang_code), it will make adding new languages simpler (if that applies), and you'll get warm fuzzy feelings from having properly normalized data (I could be wrong, but I believe the multiple columns option would violate 1NF).

另外,如果我正在设计模式,我不会打扰 Langauges 表,而是存储这两个(或者,五)字符语言代码以及每个 ArticlesLocalized 。存储和比较开销将是最小的,它不会违反任何规范化规则,它将使调试更不容易。

Also, if I were designing the schema, I wouldn't bother with the Langauges table, and instead store the two (or, possibly, five) character language code along with each ArticlesLocalized. The storage and comparison overhead will be minimal, it doesn't violate any normalization rules and it will make debugging much less painful.

这篇关于为多语言网站设计数据库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆