Sunday, May 20, 2018

Finding Code Smells Using SQL Prompt

DZone Database Zone
Finding Code Smells Using SQL Prompt
Finding Code Smells Using SQL Prompt

Using TOP in a SELECT statement without a subsequent ORDERBY clause is legal in SQL Server, but meaningless because asking for the TOP10 rows implies that the data is guaranteed to be in a certain order, and tables have no implicit logical order. You must specify the order.

In a SELECT statement, you should always use an ORDERBY clause with the TOP clause, to specify which rows are affected by the TOP filter. If you need to implement a paging solution in an application widget, to send chunks or “pages” of data to the client so a user can scroll through data, it is better and easier to use the OFFSET–FETCH subclause in the ORDERBY clause, instead of the TOP clause.

No comments:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...