T-SQL Error Handling, and a very successful run

Yesterday evening, I read the six pages on Error Trapping. It was quite dry and difficult to remember all the syntax, but I powered through with reading it and started to work on the exercises. I found a website with download links for all the code and the sample database. I ran the script to create the database and insert the data.

The first exercise showed a Primary Key violation with a duplicate key insert. I typed out the code and ran it, and it came back in less than a second with the very error they expected. The second exercise expounded on the first. Two insert statements this time, with the first insert looking as a copy of the first exercise - the insert should fail due to a primary key violation, and the second insert to succeed. However the point of the second exercise was to show that even though the first insert fails, the engine continues and inserts the second insert statement when the desired action is for SQL Server to stop and rollback the entire transaction.

Unfortunately, the code wouldn't fail or complete. It just hung. I double checked what I wrote against what the book had. It's spot on. I then looked at the code in the website for that exercise, verified that there weren't any changes between online and the book. Then I ran the code from the website and it also hung. I guess I'll get the extra effort to find out how to get the exercise to work... well, actually fail, just in a specific way.

After work, I went for a 2 mile run/walk. Previously, I'd been doing sprints of 0.07 mile paired with walking segments of 0.18 mile for 2 miles. This time, I decided to try out a comfortable jogging pace and see how long I could jog. The answer was 1 mile! I actually got really tired at 0.87, but felt like I ought to push through to get that 1 mile jog achievement. Happily, I jogged the first mile in 11:32, then jog/walked the mile back, ending the workout with 25:59, my fastest 2 mile ever! I was very pleased about it! I think I'll continue the sprinting/walking workout then a longer jog, perhaps 2 to 1.


Popular posts from this blog

Halloween Party and my costume

Board games and near the end of the gym challenge

Jose and Sons review