Does ALTER table require DROP/RECREATE of dependent view?

  • If I rename a column in a base table, is there a need to DROP and RECREATE the views that are dependent on it (that specific column) or is it sufficient to make edits to the relevant areas in the dependent view using ALTER?

  • I believe I know the answer is that renaming a column will not disrupt the view as long as the column is appropirately referenced from within the view, but just wanted to be sure!

    From BOL:

    "If a view depends on a table (or view) that was dropped, SQL Server produces an error message if anyone tries to use the view. If a new table (or view) is created, and the table structure does not change from the previous base table, to replace the one dropped, the view again becomes usable. If the new table (or view) structure changes, then the view must be dropped and recreated."

  • Sounds about right.

    The query will work if the column exists...

    Also a good reason against using select *. Because now everything refferencing can have bugs after the change and you might not catch them.

  • Let's say a view is created using "select *" and with no where clause. Is this utterly useless as well as automatically 'updatable'?

  • hxkresl (6/15/2011)


    Let's say a view is created using "select *" and with no where clause. Is this utterly useless as well as automatically 'updatable'?

    Yup.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply