January 10, 2010

Allow Users to Access a Table even when New Indexes are being created

When you are creating a new index on a table, Table locks are applied for the duration of the index operation. For large tables, index creations can take a longer time and this prevents user access to the table till the index gets created.

However if you want to allow users to access the table even when new indexes are being created, you can do so using the ONLINE option. Here’s a query that shows how:

CREATE NONCLUSTERED INDEX IX_VendorAddress_AddressTypeID
ON Purchasing.VendorAddress(AddressTypeID)
WITH (ONLINE = ON)
Note: By default, the ONLINE option is set to OFF.


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

No comments: