SQL Server and Read-Only Databases

By Chris Miller on 05 July 2000 | 1 Comment | Tags: Administration


This article discusses creating read-only databases to improve performance throughput. This can be especially handy in a web environment where many users want to view information.

Sometimes there are good reasons to have read-only databases. For internet applications, it's pretty common to have a consolidated database that provides information for users. The traditional internet model is a model which provides a lot of data to users who normally only send a small amount of data to the web. It's pretty common to have a lot of data which is read only, or at least that can be segregated into a read-only section (archive) and read-write section.

If you've got a read only database, mark it read-only in SQL Server. If you do that, then SQL Server will make some assumptions about the database, like that the database doesn't have anybody making changes on it, and SQL Server will disable locking in the database. That means less overhead, and it should speed things up a bit.

Also, if you go one step farther and actually make the database files read-only you can back up the database without shutting SQL Server down while the files are in use. Just directly back up the MDF and LDF files, and they can be restored and reattached. To mark the files read only, detach the database using sp_detach_db, use the "attrib" command to mark the files read only, and then use sp_attach_db to reattach the database.

There are a few caveats here. If you mark a database read only, it is very really and truly read only. That means that any auto-shrink options are not going to happen, and neither are automatic statistics. DBCC commands to fix database corruption will not work. As a result, you'll need to make sure that the database is already shrunk (dbcc shrinkdatabase) and that the database has all of the statistics and indexes it needs to run efficiently.

In addition, if you elect to copy the database to another path and reattach it, you'll need to make sure that the files are not marked read only or they won't attach. Why? Well, the path for the LDF file is stored inside the MDF file, so if the path needs to change, for example from one drive letter to another, then the MDF file will need to change in order to store the new path, and the LDF file will need to change in order to add the transaction log record for the change to the MDF file (funny how these things work).

Discuss this article: 1 Comment so far. Print this Article. This page has been read 38,298 times.

If you like this article you can sign up for our newsletter. We send it out each week that we post a new article. There's an opt-out link at the bottom of each newsletter so it's easy to unsubscribe at any time.

Email Address:

Email ThisSubscribe to this feedKick itSave to del.icio.usView blog reactions

Related Articles

Using xp_ReadErrorLog in SQL Server 2005 (12 May 2008)

Moving the tempdb database (5 November 2007)

Centralized Asynchronous Auditing across Instances and Servers with Service Broker (20 August 2007)

Centralized Asynchronous Auditing with Service Broker (16 July 2007)

SQL Server 2005 Best Practices on TechNet (4 December 2006)

Scripting Database Objects using SMO (Updated) (29 November 2005)

Troubleshooting Performance Problems in SQL Server 2005 (3 November 2005)

Dynamic Management Views (30 October 2005)

Other Recent Forum Posts

Failed to import Excel Data (1 Reply)

pending transactions (2 Replies)

hardware requairment for 1200 concurrent connetion (6 Replies)

Question about considering scaling while designing (5 Replies)

SQL Server Job fails (6 Replies)

database purging (6 Replies)

Installation Error - packagefortheweb (3 Replies)

Terminal Services problem (1 Reply)

Subscribe to SQLTeam.com

Weekly SQL Server newsletter with articles, forum posts, and blog posts via email:

SQLTeam.com Articles via RSS

SQLTeam.com Weblog via RSS

- Advertisement -

SQL Server Jobs