Do you use TOP for sampling in your queries?

Updated by Bahjat Alaadel [SSW] 11 months ago. See history

123
<introEmbed body={<> Top is an efficient way of identifying what a tables structure and data look like. </>} />
Video: Use TOP for sampling for SQL performance | Bryden Oliver (3 min)

Retrieving all the data in a table is a common pattern especially when someone is looking into a production incident. If the table in question is a large table, grabbing all the rows back may make the problem worse.

SELECT * FROM Users

Using TOP to reduce the number of rows being returned makes this a much less expensive operation.

SELECT TOP 20 FROM Users

TOP works with filtering and joining, so you can use it to get a sample of only the rows you are interested in.

Acknowledgements

Bryden Oliver
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star