Home All Groups Group Topic Archive Search About
Author
10 Aug 2006 3:29 PM
Jay
In SQL Server 2005 is it possible to set a table as readonly?  I know you
can mark the entire database as readonly but what about just on table?

Author
10 Aug 2006 3:48 PM
Helmut Woess
Am Thu, 10 Aug 2006 11:29:37 -0400 schrieb Jay:

> In SQL Server 2005 is it possible to set a table as readonly?  I know you
> can mark the entire database as readonly but what about just on table?

You can remove grants for insert/update/delete on this table.

bye, Helmut
Author
10 Aug 2006 3:55 PM
Adi
You can put the table on a file that is configured to be read only.

Adi
Jay wrote:
Show quote
> In SQL Server 2005 is it possible to set a table as readonly?  I know you
> can mark the entire database as readonly but what about just on table?
Author
10 Aug 2006 3:55 PM
Arnie Rowland
You can provide only SELECT permissions, and DENY UPDATE, DELETE.

GRANT SELECT ON dbo.MyTable TO UserRole
DENY UPDATE, DELETE ON dbo.MyTable TO UserRole

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


Show quote
"Jay" <msnews.microsoft.com> wrote in message
news:OJbvKHJvGHA.4972@TK2MSFTNGP05.phx.gbl...
> In SQL Server 2005 is it possible to set a table as readonly?  I know you
> can mark the entire database as readonly but what about just on table?
>
>
Author
10 Aug 2006 3:56 PM
Tracy McKibben
Jay wrote:
> In SQL Server 2005 is it possible to set a table as readonly?  I know you
> can mark the entire database as readonly but what about just on table?
>
>

Do it with permissions - DENY update and insert rights to the necessary
users.


--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
Author
10 Aug 2006 4:11 PM
Erland Sommarskog
Jay (msnews.microsoft.com) writes:
> In SQL Server 2005 is it possible to set a table as readonly?  I know you
> can mark the entire database as readonly but what about just on table?

CREATE TRIGGER readonly_tri ON tbl INSTEAD OF INSERT, UPDATE, DELETE AS
  RAISERROR('Hands off! This table is readonly!, 16, 1)
  ROLLBACK TRANSACTION
  RETURN

On SQL 2005 I believe you can set a filegroup as read-only. Thus you could
create filegroup for the table.


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
10 Aug 2006 6:36 PM
Anith Sen
>> CREATE TRIGGER readonly_tri ON tbl INSTEAD OF INSERT, UPDATE, DELETE AS
>> ..

One shortcoming with the trigger approach is that TRUNCATE and the ALTER
DDLs will bypass it.

--
Anith
Author
10 Aug 2006 10:21 PM
Erland Sommarskog
Anith Sen (an***@bizdatasolutions.com) writes:
>>> CREATE TRIGGER readonly_tri ON tbl INSTEAD OF INSERT, UPDATE, DELETE AS
>>> ..
>
> One shortcoming with the trigger approach is that TRUNCATE and the ALTER
> DDLs will bypass it.

Good point. But you can counter that by setting up a foreign key
that refers to the table.

The permissions stuff that was suggested by several does not stop an
administrator.

Of course, an admin can get around a trigger too, but at least the trigger
prevents him from changing the table by mistake.



--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
11 Aug 2006 1:31 PM
Jay
Thanks for all the replies.  What I need to do is prevent anyone (even
admins) from altering the data in the table.  Looks like my best approach
maight be a readonly filegroup.


Show quote
"Erland Sommarskog" <esq***@sommarskog.se> wrote in message
news:Xns981C3B7BBB0BYazorman@127.0.0.1...
> Anith Sen (an***@bizdatasolutions.com) writes:
>>>> CREATE TRIGGER readonly_tri ON tbl INSTEAD OF INSERT, UPDATE, DELETE AS
>>>> ..
>>
>> One shortcoming with the trigger approach is that TRUNCATE and the ALTER
>> DDLs will bypass it.
>
> Good point. But you can counter that by setting up a foreign key
> that refers to the table.
>
> The permissions stuff that was suggested by several does not stop an
> administrator.
>
> Of course, an admin can get around a trigger too, but at least the trigger
> prevents him from changing the table by mistake.
>
>
>
> --
> Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se
>
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
15 Aug 2006 11:17 AM
Locky
Jay wrote:
> In SQL Server 2005 is it possible to set a table as readonly?  I know you
> can mark the entire database as readonly but what about just on table?
move your table to a read-only file group.
nor DENY, nor TRIGGER does not protect your data from TRUNCATE.

AddThis Social Bookmark Button