在MySQL中访问查询 [英] Access Lookup in MySQL

查看:89
本文介绍了在MySQL中访问查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将表从.accdb文件移动到MySQL.在Access 2010中,我可以使用行源"查询从另一个表中获取可接受的值. (就像MySQL中的ENUM类型一样,该类型使用查询来动态填充其集合.)

I'm moving tables from an .accdb file to MySQL. In Access 2010, I could use "Row Source" query to get acceptable values from another table. (Like an ENUM type in MySQL which fills its set dynamically using a query.)

例如,对于LendedBooks表中的LendedTo列,我使用查询

For example, for the LendedTo column in the LendedBooks table, I use the query

SELECT [Members].[Name] + ' ' + [Members].[Surname]
FROM Members
ORDER BY [Members].[Name] + ' ' + [Members].[Surname];`

如何在MySQL中做到这一点?

How can I do this in MySQL?

推荐答案

在MySql中,您可以使用

In MySql you can use a foreign key constraint (i.e., relationship) to link two tables together. So the LendedTo column in LendedBooks would be a relationship to the primary key field (say, ID) of Members. When you create the relationship you can then enforce that the only allowed values are those that satisfy the relationship.

如果您有更复杂的现场要求,则可以研究检查约束的概念. MySql中不直接支持检查约束,但可以借助触发器进行模拟.

If you have more complicated field requirements, then you can look into the concept of check constraints. Check constraints are not directly supported in MySql but can be emulated with the help of triggers.

这篇关于在MySQL中访问查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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