I have a huge sql script that makes a lot of changes in my db scheme and in my data. The script includes GO commands.
Is there any way to execute the script and undo it in case of an any error?
I cannot wrap everything in transaction since there is GO commands.
You can wrap multiple batches in a transaction, you are wrong about that, but truth is that a complex upgrade script is unlikely to be possible to execute in one single transaction. Your best solution would to take a backup and if the script fails restore the database from the backup.