Link to home
Start Free TrialLog in
Avatar of mcgitsupport
mcgitsupport

asked on

Specific Read-Only rows in a SQL Server 2005 Table

Is it possible to make specific rows read-only in a table?
Avatar of wael_tahon
wael_tahon
Flag of Egypt image

I think you can achieve this in your application layer.
lets say that all records that you want to make readonly will have a column called "IsLocked" equal to "1" and in your grid you will disable the edit control based on the value of "IsLocked" column.
Avatar of mcgitsupport
mcgitsupport

ASKER

Is it possible to achieve this on the sql server side without changing the code?
Thanks..
Yes. You can deny access to the table and implement the row-level security in a stored procedure (assuming you perform all the relevant updates through a stored procedure).
Create a view on the table and give only Select rights on that view.
The scenario is that I have a table in SQL Server which is composed of data that changes every day.  So I have to store each days worth of data.  The problem is that I don't want anybody else to be changing a certain part of the existing data via an application,query or stored procedure, so I want to make certain rows read-only.  For example, from 01/01/07 to 12/31/07 all rows should be read-only.  The rest should be editable since we are in a new year.
In addition I need to keep all data in the same table so that I can run reports of the existing data.

Basically is there a function I can call within SQL Server to make certain rows to be read-only?
mcgitsupport: Whether you use views or procs to achieve this, the prerequisite is that you manage secuirty via logins, user roles and GRANT/DENY. If you are able to do that then you can achieve what you have asked for.

If you do not or cannot control security in your database then no "read-only" function is going to help. Even if such a feature existed it could presumably be turned on and off unless you restricted the rights of other users to enable or disable it at will. I hope you can see why "access control" is the right answer to your question - not "make rows read only".
dportas: I do agree with, there are no way to control it if you can't control your DB access and the only way is through your application logic
ASKER CERTIFIED SOLUTION
Avatar of mcgitsupport
mcgitsupport

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial