如何使用复合键进行SELECT? [英] how to do a SELECT with a composite key?

查看:197
本文介绍了如何使用复合键进行SELECT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有复合键的表,我想用该键进行SELECT查询,有没有一种方法可以在复合键上放置名称或进行查询而不必添加AND

I have a table with a composite key, and I want to do my SELECT query with that key, is there a way to put a name to the composite key or to do the query without having to add an AND

比方说:

SELECT * FROM MyTable WHERE PRIMARY KEY = 12345

将该主键作为复合键

推荐答案

不,没有SELECT * FROM MyTable WHERE PRIMARY KEY ='PrimaryKeyName'的概念.换句话说,谓词(WHERE子句)不允许这样做.您将需要列出谓词中的复合主键中包含的所有列.

No, there is no concept of SELECT * FROM MyTable WHERE PRIMARY KEY = 'PrimaryKeyName'. In other words, the predicate (WHERE clause) does not allow for this. You will need to list all columns that are contained within the composite primary key in the predicate.

一个潜在的解决方案是构建一个表,该表存储事实表的所有主键组合.您可以将一个标识字段添加到该表,并使其成为表上的外键约束.然后,您的谓词使用单个外键列.

A potential solution is to build a table that stores all primary key combinations for the fact table. You can add an identity field to that table and make it a foreign key constraint on your table. Then, your predicate uses the single foreign key column.

这篇关于如何使用复合键进行SELECT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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