• 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!