Answer the question
In order to leave comments, you need to log in
Substituting column values in a table for a specific user?
There is a database MSSQL, there are several tables. There is a user who can only do SELECT. Is it possible not to block the reading of a specific column, but to issue a value for it? At the same time, everything must be done transparently for the user, i.e. without changing the table name, without creating a copy of the database and copying changes to it.
Answer the question
In order to leave comments, you need to log in
this is how it should work:
create table tmp
( ID INT PRIMARY KEY,
TextVal varchar(10)
)
insert into tmp (ID, TextVal) values (1, '1')
insert into tmp (ID, TextVal) values (2, '2')
insert into tmp (ID, TextVal) values (3, '3')
create view vw_tmp
as
select ID,
CASE USER_ID()
WHEN 1 THEN TextVal
ELSE ''
END as TextVal
from tmp
If my memory serves me, then in MS SQL it is impossible to write a trigger for the Select operation.
It seems to me that in this case it is worth using a stored procedure instead of Select, then it will be possible to replace it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question