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
精彩评论