I need to find a way to control data viewed by different users. So I have five type of users, User with typeId 1 can view everything, whereas user with typeid 3 can view part of the data and so on.
Any suggestions how can I do this?
Control the data from my sql server itself,having if statements:
create procedure getAlldate(@typeid)
If @typeid=1
Begin
select * from tblUsersDetails
End
or is there another way I could do this?
You can first create X database user roles for your X types of users. Look at CREATE ROLE (Transact-SQL)
You then add users to their respective roles using ALTER ROLE (or sp_addrolemember but it is deprecated)
You can grant, deny or revoke rights on your objects to these User Roles. You grant Select on Table1 to RoleX like this:
grant select on Table1 to RoleX
If you need to give access to only part of a table or only some columns, you can first create a view :
Create View View1 As Select col1, col2, col5, col10 From Table1 Where col20 = 0
Finally you can grant rights on the view to RoleX
grant select on View1 to RoleX
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.