Link to home
Create AccountLog in
Avatar of damixa
damixaFlag for Denmark

asked on

Identity_insert on on several tables

I'm migrating an old database into another (access to SQL). I have the code for over 200 tables and obviously it is not letting me turn the Identity_insert on for more than one table in one session.

is there a way I can separate the inserts so that it runs one piece of code completely, then stops the session and starts the session again or some other way to allow me to turn the Identity Insert on for multiple tables, while running one query. Its impractical to run each query separately.

here is the code

  Set identity_insert[PBJ_2BE].[CL_bybatch_AMEX_DSCVR_2] on 
         INSERT INTO [PBJ_2BE].[dbo].[CL_bybatch_AMEX_DSCVR_2]
           ([ID]
           ,[SubDate]
           ,[TerminalID]
           ,[BatchNum]
           ,[CardType]
           ,[BatchTotal]
           ,[Transactions]
           ,[SubDate+1]
           ,[SubDate+2]
           ,[SubDate+3]
           ,[Month]
           ,[Expr1]
           ,[RControlTicketNum]
           ,[RLocationID])
    
    
    select   [ID]
           ,[SubDate]
           ,[TerminalID]
           ,[BatchNum]
           ,[CardType]
           ,[BatchTotal]
           ,[Transactions]
           ,[SubDate+1]
           ,[SubDate+2]
           ,[SubDate+3]
           ,[Month]
           ,[Expr1]
           ,[RControlTicketNum]
           ,[RLocationID]
           
           from [test7].[dbo].[CL_bybatch_AMEX_DSCVR_2]

  Set identity_insert[PBJ_2BE].[CL_bybatch_AMEX_DSCVR_2] off
        Set identity_insert[PBJ_2BE].[dbo].[DEP_1101_TRAN] on 
           
           INSERT INTO [PBJ_2BE].[dbo].[DEP_1101_TRAN]
           ([ID]
           ,[Status]
           ,[As-Of Date]
           ,[As-Of-Time]
           ,[Bank ID]
           ,[Bank Name]
           ,[State]
           ,[Acct No]
           ,[Acct Type]
           ,[Acct Name]
           ,[Currency]
           ,[IBAN]
           ,[BAI Type Code]
           ,[Tran Desc]
           ,[Debit Amt]
           ,[Credit Amt]
           ,[0 Day Flt Amt]
           ,[1 Day Flt Amt]
           ,[2+ Day Flt Amt]
           ,[Customer Ref No]
           ,[Value Date]
           ,[Location]
           ,[Bank Reference]
           ,[Tran Status]
           ,[Descriptive Text 1]
           ,[Descriptive Text 2]
           ,[Descriptive Text 3]
           ,[Descriptive Text 4]
           ,[Descriptive Text 5]
           ,[Descriptive Text 6]
           ,[Descriptive Text 7])
        
        
        
        
        Select [ID]
           ,[Status]
           ,[As-Of Date]
           ,[As-Of-Time]
           ,[Bank ID]
           ,[Bank Name]
           ,[State]
           ,[Acct No]
           ,[Acct Type]
           ,[Acct Name]
           ,[Currency]
           ,[IBAN]
           ,[BAI Type Code]
           ,[Tran Desc]
           ,[Debit Amt]
           ,[Credit Amt]
           ,[0 Day Flt Amt]
           ,[1 Day Flt Amt]
           ,[2+ Day Flt Amt]
           ,[Customer Ref No]
           ,[Value Date]
           ,[Location]
           ,[Bank Reference]
           ,[Tran Status]
           ,[Descriptive Text 1]
           ,[Descriptive Text 2]
           ,[Descriptive Text 3]
           ,[Descriptive Text 4]
           ,[Descriptive Text 5]
           ,[Descriptive Text 6]
           ,[Descriptive Text 7]
           
           from [test7].[dbo].[DEP_1101_TRAN]
            Set identity_insert[PBJ_2BE].[dbo].[DEP_1101_TRAN] off

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dsacker
dsacker
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of damixa

ASKER

Perfect, thanks