I had inadventenly locked myself out of Sharepoint by removing myself as site administrator. But, because I have access to the SQL database I was able to restore my permissions. First run the following query to find out your tp_ID. (You will have to run this on the correct Content database).
select tp_id, tp_siteadmin, tp_login from userinfo
Find your user name in the query results (you can use a WHERE LIKE clause to simplify this step). Then run the following query to give yourself permissions.
UPDATE userinfo SET tp_siteadmin = 1 WHERE tp_Id = ?
That should give you everything you need. Log into Sharepoint and you should be a Site Collection Administration