• When you run any program it must be compiled first.

    When SQL Server compiles your script without "GO" you table does not have that IDENTITY column yet, and compilation fails because of that.

    When you separate scripts by "GO" each batch is compiled separately. So, when you compile the batch which accesses that IDENTITY column it's already created by one of previous batches.

    Little hint - compiler would not mind if there would be no table at all. But it will fail if the table has incorrect structure.

    And a major advice - don't modify database schema on fly. NEVER. I mean NEVER!!!

    Remember - SQL Server is a multiuser environment. You may have 2 or more users executing different parts of the same code at the same time.

    If there is no other way to solve the problem but alter tables ask here or Google for a solution.

    _____________
    Code for TallyGenerator