将额外数据与 MySQL 列关联
我有一个典型的表,例如
id(int) name(varchar) address(varchar) date(datetime)
我还有一个引用每个验证函数的表,例如
id(int) function(varchar) fail_message(varchar)
1 email Please enter a valid email address
2 required This field can not be left blank
我希望能够将第一个表中的每一列与一个或多个验证器相关联。
我能想到的唯一方法是将 ids 填充到列名称中,例如(列名称:email;1;2)并通过 PHP 跟踪它,但这看起来很混乱。
对于关系数据库有没有好的方法来做到这一点? NoSQL 实现会更适合这个问题吗?
I have a typical table, e.g.
id(int) name(varchar) address(varchar) date(datetime)
I also have a table that references validation functions for each one, e.g.
id(int) function(varchar) fail_message(varchar)
1 email Please enter a valid email address
2 required This field can not be left blank
I'd like to be able to associate each column from the first table with one or more of these validators.
The only way I can think of doing this is to stuff the ids into the column names e.g. (column name: email;1;2) and keep track of it through PHP, but that seems very messy.
Is there a good way to do this with relational databases? Would a NoSQL implementation suit this problem better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与 Dan 所说的类似,在 sql 中实现关联的一个相对简单的方法是执行以下操作:
然后当您想要进行失败检查时,使用上表将错误消息链接到列名(例如 ' select function_id from above_table where col_name="address"') 然后查询故障表。随后可以使用具有联接的视图来组合这些表,以便单个查询就足够了。
希望这有帮助。
Similar to what Dan said, a relatively easy way to implement an association in sql would be to do the following:
And then when you want to do the failure check, use the above table to link the error message to the column name (e.g. 'select function_id from above_table where col_name="address"') and then query the failure table. These tables could subsequently be combined using a view with a join so that a single query would suffice.
Hope this helps.
将其放在另一个描述表列的表中,这很奇怪,这非常像扩展列出带有附加列的表列的表
假设如果您使用本地化字符串扩展示例,这意味着fail_message将成为fail_message_id并且表fail_message 将包含列(id、语言、消息)
put this in another table that describes the columns for tables oddly this is very much like extending the table that lists table columns with additional columns
let's say if you extend your example with say localized strings that would mean that the fail_message would become a fail_message_id and the table fail_message would have the columns (id, language, message)