SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Lock tabels


Lock tabels

Author
Message
Krasavita
Krasavita
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1943 Visits: 1894
Hello,

Can I put tabels in read only mode?

Thank you

Julia
george sibbald
george sibbald
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10264 Visits: 13687
not directly, but you could move them to a separate filegroup and make that read only, or do it via permissions (only select granted or only access via stored procs)

---------------------------------------------------------------------
Krasavita
Krasavita
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1943 Visits: 1894
Can you give me an example please
Lowell
Lowell
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27980 Visits: 39922
here's something i put together for a different post that was talking about setting a table to read only:

this is not copy/paste/execute code, but rather, amodel to use to modify and step through to comprehend what is going on.



USE [master]
GO
ALTER DATABASE SandBox ADD FILEGROUP onlyLookups
GO
ALTER DATABASE [SandBox] ADD FILE ( NAME = N'SandBox_Lookups',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\SandBox_Lookups.ndf' ,
SIZE = 2048KB ,
FILEGROWTH = 1024KB )
TO FILEGROUP [OnlyLookups]
GO
USE [SandBox]
GO
declare @readonly bit
SELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'
if(@readonly=0)
ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READONLY
GO
USE [master]
GO
declare @readonly bit
SELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'
if(@readonly=0)
ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READONLY
GO

--are we readwriteable or not?
USE [SandBox]
GO

--#################################################################################################
--toggle read only, add table, put it back
--#################################################################################################
declare @readonly bit
SELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'
if(@readonly=1)
ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READWRITE
GO
--switch db context so we can alter
USE [master]
GO
declare @readonly bit
SELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'
if(@readonly=1)
ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READWRITE
GO
--#################################################################################################
--add table
--#################################################################################################
USE [SandBox]
GO
CREATE TABLE [dbo].[CITYDATA] (
[CITYNAME] VARCHAR(28) NULL,
[COUNTYNAME] VARCHAR(64) NULL,
[STATE] VARCHAR(2) NULL,
[STATEFIPS] VARCHAR(2) NULL,
[COUNTYFIPS] VARCHAR(3) NULL,
[ZIPCODE] VARCHAR(5) NULL,
[STATETBLKEY] INT NULL,
[COUNTYTBLKEY] INT NULL,
[CBSA] AS ([STATEFIPS]+[COUNTYFIPS]))
ON onlyLookups

--#################################################################################################
--toggle read only back again
--#################################################################################################
USE [SandBox]
GO
declare @readonly bit
SELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'
if(@readonly=0)
ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READONLY
GO
USE [master]
GO
declare @readonly bit
SELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'
if(@readonly=0)
ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READONLY
GO



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Krasavita
Krasavita
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1943 Visits: 1894
Thank you,but how would you add this to table?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86420 Visits: 45233
Other way around. This isn't something you add to a table. Rather you move the table into a separate filegroup and mark the filegroup read only (tables can't be read only, only filegroups or databases)

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Krasavita
Krasavita
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1943 Visits: 1894
Thank you,How you move the table into a separate filegroup?
Lowell
Lowell
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27980 Visits: 39922
Krasavita (1/15/2013)
Thank you,How you move the table into a separate filegroup?


peek at the code i posted, which creates a new table in the filegroup.

for an existing table, you can Use create index ... with drop_existing for the clustered index and specify the desired filegroup for the place that the index must be created on. , which effectively "moves" the table to the new filegroup.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Krasavita
Krasavita
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1943 Visits: 1894
When I tried to create clustered index as you said and assign to read only file group,I get an error message:that can't save because this file group is readonly
Lowell
Lowell
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27980 Visits: 39922
Krasavita (1/16/2013)
When I tried to create clustered index as you said and assign to read only file group,I get an error message:that can't save because this file group is readonly


again, look at the code i posted.

i toggle the group to read-write, add the table/index, and then toggle it back to read only.

you will have to do the same,.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search