Suppose we have 3 tables as follows:
Table1: Column1, Column2, Column3
Table2: Column1, Column2, Columnxyz, Column3
Table3: Column1, Column2, Column3
I have a view with the following DDL:
CREATE VIEW [dbo].[View1]
AS (
SELECT 'Table1' as [Source], * FROM [Table1]
UNION
SELECT 'Table2' as [Source], * FROM [Table2]
UNION
SELECT 'Table3' as [Source], * FROM [Table3]
);
That view works flawlessly assuming all tables have the same columns.
however, in the example above, with table2 having additional column: columnxyz What would I need to change in the view union? In other words, do I have to create Table1 and Table3 with this additional column as well, or can we circumvent this by somehow dynamically appending this extra column in the view to the other tables missing it and filling it with "None" or "N/A" as default data (since Table1 and table2 don't originally have this columnxyz so there's really no data anyways)?
union all
notunion
– CharliefaceSELECT 'Table1' as [Source], [columnxyz] * FROM [Table1]
bt what do you mean i should list all the columns individually? is it because of the order? – Cataster