Hi,
i am updating some set of records in that table , after that i need to make this table read only.
So How to make a table Read Only in SQL Server?
Regards, Jeyavel N
Hi,
i am updating some set of records in that table , after that i need to make this table read only.
So How to make a table Read Only in SQL Server?
Regards, Jeyavel N
A simple alternative that would block update and insert on a specific table but still allowing delete:
ALTER TABLE mytable WITH NOCHECK ADD CONSTRAINT chk_read_only CHECK( 1 = 0 )
If you really need a table to be truly read only you could also either:
a) put it in its own database or
b) put it on a file group and mark that read only, here’s how:
USE [master]
GO
ALTER DATABASE [csvtosp] ADD FILEGROUP [READONLYTABLES]
GO
ALTER DATABASE [csvtosp] ADD FILE ( NAME = N'mydb_readonly_tables', FILENAME = N'G:\SQL2005DATA\mydb_readonly_tables.ndf' , SIZE = 3072KB , FILEGROWTH = 1024KB ) TO FILEGROUP [READONLYTABLES]
GO
USE csvtosp
GO
DROP TABLE mytable
CREATE TABLE mytable (
somedata char(8000) not null
) ON READONLYTABLES
GO
For more details on this subject, go here:
If you want it as read only to the general public, but still want to be able to edit the table at a later date, you may want to consider creating multiple users for the database and granting different permissions to that database - ideally you should be doing this anyway and not allow the general public access to alter table, truncate etc.
Number 3 is probably best practice. For example, if your connection is db_owner for example then the trigger can be disabled the trigger or move the table to a different filegroup anyway.