How to implement LIMIT cluase for SQLServer at table level access?

Anonymous
2023-08-03T20:05:17.94+00:00

Hi I am trying to implement LIMIT clause at SQLServer database level. The objective is to make sure that no one has the full scan of the table, instead can only scan 10 records or so.

Azure SQL Database
{count} votes

2 answers

Sort by: Most helpful
  1. Alberto Morillo 34,671 Reputation points MVP Volunteer Moderator
    2023-08-03T20:46:32.2733333+00:00

    MySQL supports the LIMIT clause to select a limited number of records, while Transact-SQL for SQL Server and Azure SQL uses TOP.

    Below code shows how SQL Server implements the same concept.

    SELECT TOP 3 * FROM Customers;
    

    And below code shows how MySQL implements the LIMIT clause to have a limit on the numbers of rows returned.

    SELECT * FROM CustomersLIMIT 3;
    
    0 comments No comments

  2. Olaf Helper 47,436 Reputation points
    2023-08-04T06:35:40.66+00:00

    LIMIT clause at SQLServer database level.

    That's not possible, a result limitation is defined on query level and the user must define it on his own#

    You can create views/stored procedure returning only a limited result set, then grant access for the users on that views/SP, but not on the base tables.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.