473,791 Members | 3,071 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Maximum UNION statements in a query

Wondering if there is a physical or realistic limitation to the number
of UNION statements I can create in a query? I have a client with
approx 250 tables - the data needs to be kept in seperate tables, but I
need to be filtering them to create single results sets. Each table
holds between 35,000 - 150,000 rows. Should I shoot myself now?

lq

Dec 17 '05
15 16775
And the partitioned view performs better than just a sproc that limits
the range, but without the parameter issues?

Dec 19 '05 #11
Yes. I started doing this already. Thanks for the ideas on this.
When it's all in one table, and users are running select queries
against this table (no updates, no inserts and no deletes) will
performance be effected if multiple users are running similar select
queries against this table at the same time?

Dec 19 '05 #12
Yes, I have started doing this already. A question, if multiple users
are running select queries against this table (not inserts, not updates
and not deletes) will performance decrease with the number of users
running select queries at the same time - most queries will probably
return 1-350 rows?

Dec 19 '05 #13
If the queries return less than 350 rows (less than 0,01% of the big
table), it's probable that some index may be used, if it exists.
In this case, the performance impact should be insignificant.

If the query returns much more rows (or if an appropriate index does
not exist) SQL Server may perform a table scan. In this case, scanning
one big table (if you use a big table, and 250 views) would be slower
than scanning one (or a few) smaller tables by querying the partitioned
view, also specifying a condition on the partitioning column (if you
use 250 tables and a partitioned view).

Razvan

Dec 20 '05 #14
Stu
To be honest, I don't know. I never considered doing it the other way,
because conceptually, by using the partiitioned view, my application is
only dealing with one entitiy. It just seemed easier to manage than
building intelligence into my INSERT and UPDATE statement to determine
where the data belongs. I just INSERT into the view, and the check
constraints handle the slicing and dicing. If I need to archive a
day's worth of data, I copy the appropriate table to my archive, drop
the table, and rebuild the view.

Of course, having re-read this thread, I'm not 100% sure that
partitioned views will support the number of tables you need. One of
the limitations of using my method of dynamically building the view is
that the view statemnt is a varchar(8000) statement; if there an
excessive number of tables, the view may not be built correctly. I use
a similar method to the code snippet you posted above; the base SQL
statement you posted has about 40 characters in. 40 * 251 = 10040, so
the snippet you suggest will probably run into the same issue.

I have seen some tricks to get around this limitation of dynamic SQL
(like EXEC (@sql1 + @sql2), but haven't tried them; there are solutions
to every problem, however. The questions I would ask myself would be:

1. How often am I going to add new tables to this structure?
2. What's the easiest way to manage interaction with the data?
3. What's the differentiation between the slices?
4. How often will I need to retrieve information from multiple slices
at once?

Just thinking aloud.

Dec 20 '05 #15
I just finished running un update query on this table - which currently
6.5 is million rows. The update query inserted a single digit into a
tinyint column for every row based on a join on a char(1) column in the
table -- this update query took 14 1/2 hours!!!!
I'd call this unworkable...

Dec 21 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
5510
by: (Pete Cresswell) | last post by:
I've got some SQL that works as far as returning a recordset from a series of UNION statements. viz: SELECT whatever UNION this UNION that UNION other
3
5374
by: Edward | last post by:
I am having conceptual trouble with the following query: select r.ServiceID,r.ContractID,sum(Total) from ( select csc.ServiceID,c.ContractID, sum(csc.ContainerMovement) as Total from iwms_tbl_CustomerSiteContainers csc, iwms_tbl_ContractLines cl, iwms_tbl_Contracts c,
0
5041
by: Stuart E. Wugalter | last post by:
Hello: I have a form (record source: tblMasterTable) containing a MEMO field named "FASTA." I have used a double-click event to trigger a macro that runs the following query: SELECT SNPID, OrderNum, RefNo, FASTA FROM tblMasterTable WHERE Forms!frmFASTA!FASTA=FASTA;
3
3424
by: Chip R. | last post by:
Hi, This isn't really an access question, but as I'm really new to SQL I don't know where I would post this. Any suggestions on that would also be helpful. Now on to the question... I am trying to extract data from a Timberline database through an OBDC driver to MS Excel. I'm using Microsoft Query and a crude knowledge of SQL to build my query.
1
7781
by: CrystalDBA | last post by:
I usually design applications in SQL Server and Crystal Reports. I now need to create a crystal report on an MS Access database. I have two tables: Services: Date datetime Entry text Amount number (should be 4 records)
5
3297
by: Lyn | last post by:
This one is difficult to explain, so I will cut it down to the basics. I have a major table 'tblA' which has an autonum field 'ID-A' as primary key (of no significance to users). 'tblA' contains many fields including picture and memo fields. The main user-selectable field is 'NameA'. There is also a crossreference table (let's call it 'tblB') which provides a secondary method of accessing records in 'tblA'. The main fields in 'tblB'...
2
1912
by: Jonathan Woods | last post by:
Hi there, I have no idea why the following TSQL does not work.Any Idea? I am using SQL 2000 Server CREATE PROCEDURE RptDailySummary2 @FromTxDate DATETIME, @ToTxDate DATETIME AS BEGIN
5
2512
zachster17
by: zachster17 | last post by:
Hi everyone, First of all, sorry for the massive amount of SQL I am about to type. I have a database that has a "lives" table of insured employees and then another table (that links to the lives table) that has all the dependents of the employees. I have also have an alternate ID table in case an employee has more than 1 id. I have to export all the data into a fixed-text-length file with very combination of the above: meaning all lives,...
5
2470
by: slenish | last post by:
Hello all, I am wondering if its possible to do a Union All Query for 1 table instead of mulitiple tables. I have 7 columns that im trying to Union. I have it working to an extent right now but its way to slow. I'm wondering what I can do to speed it up. (Im sorting threw about 300,000 records)(Time it takes is a min or more) I also noticed that its doubling the record count when i do it this way which could be why its taking so long. ...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.