Link to home
Start Free TrialLog in
Avatar of lankapala
lankapala

asked on

t-sql row permssion

Hi,
I have create user "qry" and create table Sales.
I need to give access this user only sales year 2017, i don't want to show 2016<= sales.
How to do that?
Best regards
Avatar of HainKurt
HainKurt
Flag of Canada image

maybe you can create views as

create view sales_2016 as
select * from sales where saleyear=2016;

and give select permission to the view instead of table
Avatar of lankapala
lankapala

ASKER

Sorry, i'm looking for give using table. i think we can use trigger,but not sure how
Avatar of arnold
Does the user connect to db SQL login, or there is a login to a web based interface, and you want to restrict within the app?

Understanding how users access your data.
You could create an SQL login. Then on the database, only grant it access rights to the one table where the data is. On the rights level, you either grant a user rights to query data ir not. You can not limit what data they access .....

Hainkurt provided you the answer to pull/review ...
What are you looking for this user to do.with the data?
Sorry, i'm looking for give using table. i think we can use trigger,but not sure how

there is no such thing like restrict a user to see only some data!
either you give select or not!

trigger cannot do such things...

maybe a stored procedure... but it is not easier than view solution...

creating a view and give select permission to that user looks only way...
if i can do with view, i never asking question.
i knew it's possible, i saw some code do this trick. it's ok i will check and let you guys know.
so what you are saying is you have a table sales

when you login with user usr1 and run

select * from sales

you get only sales from 2017

and you login with user other than usr1 and run

select * from sales

you get all records from sales...

is that what you want, without any proc/view?
yes
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.