简体   繁体   English

为什么我不能将电子邮件正文存储在关系数据库中?

[英]Why can't I store email bodies in a relational database?

Say I define a table users with a column for email messages where I dump the whole message as a string. 假设我定义了一个表users ,该表的users具有一列电子邮件消息,在其中我将整个消息作为字符串转储。

It would be ugly and messy but would it work? 这将是丑陋和混乱的,但是行得通吗? What would be the consequence of doing this? 这样做的后果是什么?

I am asking because I read that unstructured data cannot be stored in a relational database and an email body is highly unstructured but it in itself is just a string. 我之所以问是因为,我读到非结构化数据无法存储在关系数据库中,并且电子邮件正文是高度非结构化的,但它本身只是一个字符串。

Yes, you can put the whole email into a "text" or "string" column in the database. 是的,您可以将整个电子邮件放入数据库中的“文本”或“字符串”列。

Even better, many databases support text search functionality. 更好的是,许多数据库都支持文本搜索功能。 So you could build a text index and be able to search through the email body efficiently. 因此,您可以建立文本索引并能够有效地搜索电子邮件正文。

The downside is that the rows are bigger, which can slow down using the table. 缺点是行较大,使用表可能会减慢速度。 If the emails are repeated, then you probably want a separate table for the emails, with an id representing the text. 如果重复发送电子邮件,那么您可能需要一个单独的电子邮件表,其中的id代表文本。 Another table would show which users received which email. 另一个表格将显示哪些用户收到了哪个电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM