Bungo
Bungo

Reputation: 11

Why did renaming a table in SQL Server also update a view?

Had a view created that referenced tableA. Renamed tableA to tableA_old and created a new tableA. The view is now referencing tableA_old. How did this happen?

It's SQL Server 2016 (running in SQL Server 2008 mode)

Upvotes: 0

Views: 41

Answers (1)

Bart Hofland
Bart Hofland

Reputation: 3905

I could not reproduce your issue. I just made a small test database, created a table and a view, renamed the table and created a new one with the original name, and the view just selects the data from the new table. As expected. What do you mean by "running in SQL Server 2008 mode"? Do you mean the compatibility level of the database you are using? Or something else? But I don't think it would matter anyway; this behavior should be the same in all versions of SQL Server as far as I know... Very strange.

Are you really sure the view references the old table? You might want to script your view to a new query editor window to be sure... If your new table contains the same data as your old table, it's difficult to see the difference using just a SELECT query.

Upvotes: 1

Related Questions