Answers

Question and Answer:

  Home  MS SQL Server

⟩ What Happens If You Delete a Table That Is Used by a View?

Assuming that you have a table which is used by a view, and you try to delete that table. SQL Server will let you delete the table without any trouble.

But that view will become invalid. The tutorial exercise below shows you what happens to the view, when the underlying table is deleted:

USE GlobalGuideLineDatabase;

GO

SELECT * INTO ggl_links_copy

FROM ggl_links WHERE counts > 0;

GO

CREATE VIEW ggl_links_view AS

SELECT * FROM ggl_links_copy;

GO

SELECT COUNT(*) FROM ggl_links_view;

GO

50015

DROP TABLE ggl_links_copy;

GO

SELECT COUNT(*) FROM ggl_links_view;

GO

Msg 208, Level 16, State 1, Line 1

Invalid object name 'ggl_links_copy'.

Msg 4413, Level 16, State 1, Line 1

Could not use view or function 'ggl_links_view'

because of binding errors.

 152 views

More Questions for you: