How to I add column for a table online?

  • Hello!

    I have a database with a big tabla (600 millions row).

    My task: add 3 column for this table online. (ALTER TALE table_name ADD column_name INT NULL).

    How to I add column for this table online?

    My problem:

    Session 1:

    BEGIN TRAN

    SELECT columns FROM table WITH (xlock) WHERE id = 3

    -- This is a row lock

    Session 2:

    ALTER TABLE table ADD column_name INT NULL

    -- This is a Sch-M lock, wait for Session 1

    Session 3:

    UPDATE table SET columns = values WHERE id = 2554

    -- wait for Session 2

    (But Session 1 and Session 3 are compatibility without session 2).

  • My task is done, with this idea:

    1.) Using lock_timeout on the session

    2.) Search object with sp_lock stored procedure

    If the object is not locked, then alter table ... add column

    Thanks

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply