USE [master]GOALTER DATABASE SandBox ADD FILEGROUP onlyLookupsGOALTER 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]GOUSE [SandBox]GOdeclare @readonly bitSELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'if(@readonly=0) ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READONLYGOUSE [master]GOdeclare @readonly bitSELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'if(@readonly=0) ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READONLYGO--are we readwriteable or not?USE [SandBox]GO--#################################################################################################--toggle read only, add table, put it back--#################################################################################################declare @readonly bitSELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'if(@readonly=1) ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READWRITEGO--switch db context so we can alterUSE [master]GOdeclare @readonly bitSELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'if(@readonly=1) ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READWRITEGO--#################################################################################################--add table--#################################################################################################USE [SandBox] GOCREATE 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]GOdeclare @readonly bitSELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'if(@readonly=0) ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READONLYGOUSE [master]GOdeclare @readonly bitSELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'OnlyLookups'if(@readonly=0) ALTER DATABASE [SandBox] MODIFY FILEGROUP [OnlyLookups] READONLYGO
We walk in the dark places no others will enterWe stand on the bridge and no one may pass