0

I have multiple tables created for each date to store some information for each date. For example History3108,History0109..etc All of these tables share same schema. Some time i need to query multiple tables and get the rows and count of records. What is the faster way of doing this in oracle and SQL Server?

Currently i am doing like this...

  1. When i need count of multiple tables: Select count(*) for each table and add
  2. When i need records of multiple tables: select * from table1, select * from table2 (Basically select * for each table.)

Would this give better performance if we include all of the queries in one transaction?

4
  • Why not keep it all in one single table? Commented Sep 1, 2014 at 14:10
  • @mxix probably to archive data each day to different tables (by looking at the example names) Commented Sep 1, 2014 at 14:11
  • Are you using unions? I guess 3108 and 0109 are dates (31st August and 01st September?). By the look of it you might have a large number of tables? And the number of tables are growing? Please add this information to the question. Commented Sep 1, 2014 at 15:11
  • Yes...large number of tables. For each day one table Commented Sep 1, 2014 at 17:26

1 Answer 1

1

With UNION you can get records from multiple tables that shares the same datatype group and column names. For example, if you want to see all records from multiple tables:

(select * from history3108)
union all
(select * from history0109)
union all
(select * from history0209)
/* [...] and so on */

and if you want to count all records from these tables:

select count(*) from (
  (select * from history3108)
  union all
  (select * from history0109)
  union all
  (select * from history0209)
  /* [...] and so on */
);
  1. Oracle Docs - The UNION [ALL], INTERSECT, MINUS Operators
Sign up to request clarification or add additional context in comments.

1 Comment

Does this give better performance compared to selecting tables individually?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.