sql execution getting failed if Data already present
thamulansar opened this issue · 1 comments
thamulansar commented
$Command = "Invoke-Sqlcmd -ServerInstance '$Server' -Database '$Database' -InputFile '$SqlCmdFile' -OutputSqlErrors 1 -ErrorAction Stop";
Scenario : lets say 5 SQL insertion task is there inside the folder as 5 files.
If issue with first SQL command file , Second command wont run and throw error
example ::: Cannot insert duplicate key in object 'dbo.Table_TEST'. The duplicate key value
So next sql cmd wont run in the for loop.
Please have a check.
Thanks
DrJohnT commented
Deployment scripts should always error when a script errors. That way you know when something has gone wrong. Hence the code has -ErrorAction Stop
Do deal with this
- add your own TRY-CATCH block to your own T-SQL script!
- add a test to check if the key already exists before inserting
Ultimately, think about what you are doing before raising non-issues.