Running a basic select on SQL Sever asks for column name that doesn't exist, why?

StackOverflow https://stackoverflow.com/questions/23667441

  •  22-07-2023
  •  | 
  •  

Domanda

We had another developer come through and complete some work for us. Unfortunately he didn’t work well within our team and management let him go.

Because of this now I’m stuck debugging his code and undoing work that was done. He did not document his code (one of the reasons he was let go), rarely notating anything, therefore I have no idea where to begin looking.

When I run a basic SELECT on two specific tables in our DB:

SELECT * FROM table_name

Using SQL Server Management Studio I get this...

Msg 207, Level 16, State 1, Line 1
Invalid column name 'eventTime'.

There was an eventTime column but wasn’t necessary and wasn't being used in any PHP file, however it seems somehow directly tied to the table now and I have no idea where to look to find it. The error message provided is pointing to my SELECT statement, but there is nothing wrong with it, nor does it even reference the eventTime column.

I’ve looked and there don’t seem to be any triggers or stored procedures referencing this table. Is there another way I can try to track this down?

È stato utile?

Soluzione

This sounds like a hard'ish problem. Here are some ideas.

My first thought is that table_name is a view, and somehow the view has gotten out-of-sync with the underlying table definitions. I have seen problems with types in some circumstances. I imagine the same could happen with column names.

The next thought is that table_name has computed columns. In this case, the computed columns could be using a function and the function call could be generating the error. I cannot think of any other way to run code with a simple select.

I don't think the problem would be a foreign key constraint unless. So, a third option is that a foreign key constraint is referencing a table in the same database but a different schema. The different schema could have permissions that make the table inaccessible.

For any of these, scripting out the definition in SSMS will help you fix the problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top