I have to run multiple sql files in order. sql1 files uses temp tables to store the constraints. Once it is done with the insert from sql3, sql4 uses the constraints stored in a temp table by sql1 to restore the constraints. I want to do this using an automated powershell scripts. Basically I am looking for a way to execute multiple sql queries using powershell inside a single transaction
sql1= "D:\DB\00-StoreConstraints"sql2= "D:\DB\01-DropConstraints"sql3= "D:\DB\03-insert"sql4= "D:\DB\05-RestoreConstraints"
This is how I am calling these sql files:
Invoke-Sqlcmd -inputfile "D:\DB\00-StoreConstraints.sql" -ServerInstance localhost -$(DBUserName) BrightChoicesPortal_User -Password $(Password) -QueryTimeout 0

sequencial couplingand usingglobal temp table. Withmssqlclears global temp table##when the creator session is closed, In your case eachInvoke-SqlCmdcreates and close a new SQL Session. See (stackoverflow.com/questions/3887989/…). I would suggest to combine the files into 1 and run the full file in a single command.