没有引用的 SQL 视图

发布于 2024-12-03 19:23:58 字数 270 浏览 0 评论 0原文

我们在 SQL Server 2008 R2 中有一个包含 20 列的表 T。四列是来自其他四个固定(ID,Value)表的简单外键。

我们现在想要的就是创建一个新的 VIEW,并将 T 的四个 foreign-key-columns 替换为相应的 Values。其余 16 列应保持不变。

请问,如何在SQL中以最优雅的方式实现这一点?

We have in SQL Server 2008 R2 a table T with 20 columns. Four columns are simple foreign keys from four other fixed (ID, Value) tables.

All we want now, is to create a new VIEW with those four foreign-key-columns of T replaced by those corresponding Values. 16 remaining columns should be untouched.

Please, how to achieve that in SQL in the most elegant way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2024-12-10 19:23:58

只需连接 4 个相关表即可,没有快捷的方法;

SELECT
  T1.Value as T1Value,
  ...
  T4.Value as T4Value,
  T.fld1
  ..
  T.fld16
FROM
  T
INNER JOIN T1 ON T.T1_ID = T1.ID
...
INNER JOIN T4 ON T.T4_ID = T4.ID

Simply join the 4 related tables there isn't a shorthand way of doing it;

SELECT
  T1.Value as T1Value,
  ...
  T4.Value as T4Value,
  T.fld1
  ..
  T.fld16
FROM
  T
INNER JOIN T1 ON T.T1_ID = T1.ID
...
INNER JOIN T4 ON T.T4_ID = T4.ID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文