开发者

SQL View without references

开发者 https://www.devze.com 2023-04-03 19:50 出处:网络
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.

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 co开发者_运维问答rresponding Values. 16 remaining columns should be untouched.

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消