Can I change table structure in a transaction and then roll it back if there is an error?
Yes, this is possible.

Most DDL statements can be rolled back in SQL Server (There are a few exceptions such as CREATE DATABASE)