Mysql数据库中的多语言类别标题 [英] Multi-language Category Titles in Mysql Database

查看:221
本文介绍了Mysql数据库中的多语言类别标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是寻找一些建议。



那些不想全部阅读的人的摘要:创建一个仅包含一个auto_increment列的表合理的想法?



详细信息:



我通常会在数据库中管理多种语言,数据及其在语言上的描述。例如:

 表:MyObject(id auto_increment,height,width,depth。PK = id)
表: MyObjectDescription(id,language,description。PK = id,language)

两个id字段对应,我有数据,如:

  MyObject 
+ ---- + -------- + - ------ + ------- +
| id |高度| width |深度|
+ ---- + -------- + ------- + ------- +
| 1 | 10 | 10 | 20 |
| 2 | 5 | 6 | 7 |
+ ---- + -------- + ------- + ------- +

MyObjectDescription
+ --- + ---------- + ----------------- +
| id |语言|描述|
+ ---- + ---------- + ----------------- +
| 1 | EN |第一个对象|
| 1 | IT | Primo Oggetto |
| 2 | EN |第二个对象|
| 2 | IT | Secondo Oggetto |
+ ---- + ---------- + ----------------- +
我的问题是我有一些数据库对象有 数据 > 描述。



例如;类别被简单地定义为id和文本描述。我可以使用像MyObjectDescription表的单个表,但是我必须自己生成id,因为我不能使用auto_increment列。这也会引发竞争条件错误或表锁定问题的可能性。或者,我可以使用另一个像MyObject这样的表,它只有一个auto_increment列...



我的疑问是:单列只是为了模拟序列合理的想法?还是只是愚蠢的?请注意,我的框架包含自动将对象表连接到描述表的逻辑。



感谢任何输入/想法。



Gareth

解决方案

使用 MyObject(id)



除非您将这些对象与数据库的其余部分隔离,否则您将需要包含 id 单独,所以它可以被FOREIGN KEY引用。



即使孤立,密钥的执行也可以证明单独的表。没有它,你不得不以某种方式生成一个新的 id ,同时防止并发事务生成相同的 id 不同的对象。明确的方法是锁定整个表(并选择MAX + 1),但会破坏可扩展性。最好只有一个单独的表,IMO。如果您在InnoDB下群集,那将只是一个B-tree无论如何。


just looking for a bit of advice.

Summary for those who don't want to read it all: Is creating a table with just one single auto_increment column a reasonable idea?

Details:

I normally manage multiple languages in the database, with separate tables for the object's data and its descriptions in language. For example:

Table: MyObject (id auto_increment, height, width, depth. PK = id)
Table: MyObjectDescription (id, language, description. PK = id, language)

The two id fields correspond, so I have data like:

MyObject
+----+--------+-------+-------+
| id | height | width | depth |
+----+--------+-------+-------+
|  1 |     10 |    10 |    20 |
|  2 |      5 |     6 |     7 |
+----+--------+-------+-------+

MyObjectDescription
+----+----------+-----------------+
| id | language | description     |
+----+----------+-----------------+
|  1 | EN       | First object    |
|  1 | IT       | Primo Oggetto   |
|  2 | EN       | Second object   |
|  2 | IT       | Secondo Oggetto |
+----+----------+-----------------+

My problem is that I have certain database objects which have no data apart from the description.

For example; a Category is defined simply as an id and a text description. I could use a single table like the MyObjectDescription table, but then I would have to generate the id myself, as I wouldn't be able to make use of the auto_increment column. This would also raise the possibility of race condition errors, or table locking problems. Or, I could use another table like MyObject which just has a single auto_increment column...

my doubt is: Is using a table with a single column just to simulate a sequence a reasonable idea? Or is it just plain stupid? Be aware also that my framework contains logic that automatically joins the object table to the description table.

Thanks for any input/ideas.

Gareth

解决方案

Use MyObject (id).

Unless you have these objects in isolation from the rest of the database, you will need the PK comprised from id alone, so it can be referenced by FOREIGN KEYs.

Even in isolation, the enforcement of key would justify the separate table. Without it, you'd have to somehow generate a new id while preventing concurrent transactions from generating the same id for a different object. Obvious way to do it would be to lock the whole table (and select MAX+1), but that destroys scalability. It's better to just have a separate table, IMO. If you cluster it under InnoDB, that'll be just a single B-Tree anyway.

这篇关于Mysql数据库中的多语言类别标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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