At the top of my query I have a few statements that drop tables if they exist, such as:
IF OBJECT_ID('dbo.vanguardsummary', 'U') IS NOT NULL
DROP TABLE dbo.vanguardsummary;
Later on I drop a particular column from one of the newly dropped and recreated tables:
alter table vanguardsummary drop column SRDid_
But sometimes when I try to rerun the whole script, I get this error:
Msg 207, Level 16, State 1, Line 191
Invalid column name 'srdid_'.
Why is it throwing this error (on a line much farther down) for a table that I am dropping at the very top of the script?
When the whole script runs, it will run again just fine. This happens when the script query is interrupted and I try to fix it and run it again. I have to run the drop table statements by themselves in order to get the query to execute again, and then the entire query will execute. What is wrong with my syntax? Any extra advice is appreciated as I am just starting to learn SQL.