开发者

SQL View without references

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜