SQL Server Invalid Column name after adding new co

2019-01-21 19:17发布

问题:

I just added an identity column to an existing table with data through the SSMS Designer, the table updates fine and I can run a select query against it successfully, but after the query finishes I noticed that the new column is underlined in red with an error indicating it's an invalid column name.

Why does this occur? I would expect the query to fail if the column was invalid.

Does the SSMS keep some type of internal reference to the old table that must be flushed?

I tried closing the DB connection and reopening it, but still the same error. Not sure what I'm missing here.

SELECT TOP 100 
[PRIMARY_NDX_Col1],
[NEW_Col], --QUERY EXECUTES SUCCESSFULLY, BUT THIS IS UNDERLINED RED AS AN INVALID COLUMN
[Col3]
FROM [dbo].[MyTable]

回答1:

you can either

  • Press CTRL+SHIFT+R

OR

  • Go to Edit >> IntelliSense >> Refresh Local Cache


回答2:

In Sql Server, Just Go to Edit >> IntelliSense >> Refresh Local Cache



回答3:

I tried this but does not work: in the below code: SET [Scope] = 1, [Scope] is highlighted as invalid column:

alter table [#DELTADATA] add [Scope] bit , [FinalProposedCustName] varchar(300) 

SettingScope:

UPDATE [UKiPFS].[#DELTADATA]
SET    [Scope] = 1
FROM   [UKiPFS].[#DELTADATA] AS a
       INNER JOIN [UKiPFS].[Scope] AS b
               ON a.[Flow] = b.[Flow]
              AND a.Entity = b.Entity
WHERE  b.In_Scope = 'Y'