It’s usually something simple that’s overlooked that ends up causing the biggest troubleshooting headache. Let me explain. I was creating a test database called “testDB” with a test table called “testTable” (yes I know, I put a lot of thought in the naming of these objects) and when I tried to insert data into this new testTable I got the following error:
Msg 208, Level 16, State 1, Line 1 Invalid object name ‘testTable’.
The answer is extremely simple and kind of embarrassing to admit.
When I created the testDB I was in the Master database. Then I forgot to “use testDB;” and proceeded to create the testTable. After creating the testTable, I did a “USE testDB;” and ran the INSERT INTO command. That’s when it failed.
Now if you’re confused as I was, this is why it failed:
After creating testDB, and before creating testTable, I was still in the Master database. SO what actually happened was I created the testTable inside of the Master database (look at snapshot below). Doh!
I dropped the testTable inside the Master database, switched over to testDB, created the testTable, ran the insert command and everything worked fine.
Don’t overlook the small things. Pay attention to what database you’re in. :)