I have 40 Tables - Table1, Table2 , Table3 ... Table40, all having same columns .
These tables contains distinct data and to identify each table's data , I have a column Reporting_Type
which have different value for each table.
For example: column Reporting_Type
of Table1
has value Reportin_Type1
and so on.
Please note that each table contains 2-3 million records.
I need to create a view which combines the data from all the tables.
I have simply applied UNION ALL and put the following query :
CREATE VIEW ALL DATA
AS
SELECT
COLUMN1, COLUMN2, COLUMN3, REPORTING_TYPE ..., COLUMN 40
FROM
TABLE1
UNION ALL
SELECT
COLUMN1, COLUMN2, COLUMN3, REPORTING_TYPE ..., COLUMN 40
FROM
TABLE2
UNION ALL
SELECT
COLUMN1, COLUMN2, COLUMN3, REPORTING_TYPE ..., COLUMN 40
FROM
TABLE3
....
SELECT
COLUMN1, COLUMN2, COLUMN3, REPORTING_TYPE ..., COLUMN 40
FROM
TABLE40
The above query takes a lot of time to fetch the data from all the tables.
Could any please suggest any performance tuned query or any other way to create this view in SQL Server 2012?
Apologies if any one find this question too Naive. I am new to database. Kindly let me know if more information is required.