Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a limit to how long a SQL query can be in SQL Server? [duplicate]

Possible Duplicate:
Maximum size for a SQL Server Query? IN clause? Is there a Better Approach

I Googled for a while and can't find whether there's some hard limit on how huge query strings can be in SQL Server. I mean what if I build a 100 million character query - will it run or will the server just drop it as too long?

Is there a limit to how long SQL query can be (in terms of characters or tokens or whatever like that) in SQL Server?

like image 945
sharptooth Avatar asked Sep 08 '11 08:09

sharptooth


People also ask

Is there a limit to how long a SQL query can be?

This limit is 65,535.

How long is too long for a SQL query?

The total length of the SQL request exceeds the maximum defined length (default=2MB). Although the SQL specification does not define a specific length limitation, SQL request that exceeds this length usually indicates a buffer overflow attempt.

Does SQL Server have a limit?

The SQL SELECT LIMIT statement is used to retrieve records from one or more tables in a database and limit the number of records returned based on a limit value. TIP: SELECT LIMIT is not supported in all SQL databases. For databases such as SQL Server or MSAccess, use the SELECT TOP statement to limit your results.

How many queries can SQL Server handle per second?

On one of our high-end servers, we see that SQL Server is able to process 3000-4000 queries per second. On our lower-end servers, it's at about 500 queries per second. SQL Server is not discarding your other requests.


1 Answers

I never encountered a problem of SQL query being too long in terms of number of characters, but there is a maximum number of tables a query can reference (256) and I hit this limitation a few times.

Have you ever encountered a query that SQL Server could not execute because it referenced too many tables?

UPDATE
In recent versions of SQL Server, the number of tables per SELECT statement is limited only by available resources.

like image 78
Marek Grzenkowicz Avatar answered Nov 15 '22 10:11

Marek Grzenkowicz