为多语言网站设计数据库模式

编程入门 行业动态 更新时间:2024-10-22 19:31:37
本文介绍了为多语言网站设计数据库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: 多语言数据库设计的最佳做法是什么?

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

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.

更多推荐

为多语言网站设计数据库模式

本文发布于:2023-10-18 13:07:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504312.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网站设计   多语言   模式   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!