Results 1 to 3 of 3

Thread: Database Locking

  1. #1

    Thread Starter
    Hyperactive Member DaveR's Avatar
    Join Date
    Mar 2001
    Location
    Ireland
    Posts
    268

    Database Locking

    Hi,

    I am trying to add a new column in the enterprise manger to a table.
    The table contains a very large number of rows - when I try to add the column the entire database gets locked.

    What is the best way to temporarily remove all locks from a table?

    Thanks
    DaveR

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Database Locking

    Quote Originally Posted by DaveR
    Hi,

    I am trying to add a new column in the enterprise manger to a table.
    The table contains a very large number of rows - when I try to add the column the entire database gets locked.

    What is the best way to temporarily remove all locks from a table?

    Thanks
    You really should not add a column with EM while users are in the DB - especially a large table.

    We did this once with a table with 3+ million rows - it took 30 minutes to add the column.

    EM copies the table to temp space - drops the table - creates a new table - all very ugly stuff.

    If you are adding the column at the end of the table, use QUERY ANALYZER to ALTER TABLE - do not use EM if you can avoid it!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Database Locking

    If you add the column on with no defaults and allow nulls then SQL Server will add it instantly without the use of a temp table.
    We do it this way and then update the table in chunks afterwards if we needed to have the column populated for existing data.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width