简体   繁体   中英

how can i restrict a database user to only access top 100 records of a table

Let's say I have a database named as db1 and a table with 10000 records, and I have a user named user1 in the database.

Then if user1 enters a query in MS SQL server:

select * from tb1, then it should return only 100 records.

there is only option to grant read or write permission to whole table.

This is too long for a comment.

I don't think there is any built-in database method for doing this. Often, applications will "page" results. Iff the application runs in select * from tbl1 , then the application only fetches 100 rows. Note: There is no concept of "top rows" in SQL without an order by clause. SQL tables represent unordered sets.

If you want to limit users to seeing only 100 rows, then you can use a view:

create view v_table as
   select top 100 t.* from tbl1 t;

Also note that without an order by clause, this might return different rows on different executions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM