Select a constant from the tables without the additional column, exactly the same as you are already doing for [Source]
. However you will have to list the columns explicitly since the additional column is not first or last. As a best practice you should always list your columns anyway.
CREATE VIEW [dbo].[View1]
AS (
SELECT 'Table1' as [Source], Column1, Column2, 'N/A' AS ColumnXYZ, Column3
FROM [Table1]
UNION ALL
SELECT 'Table2' as [Source], Column1, Column2, ColumnXYZ, Column3
FROM [Table2]
UNION ALL
SELECT 'Table3' as [Source], Column1, Column2, 'N/A' AS ColumnXYZ, Column3
FROM [Table3]
);
Note, I've used UNION ALL
because UNION
will attempt to-duplicate your data, which normally you don't want, and it suffers a performance penalty for doing so. Personally I always handle an de-duplication/grouping in other ways.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…