0

I am looking a script which allows me to add single column to multiple views. I am using SQL Server. For Ex. I have view1, view2, view3 with column1, column2.

I need to add column3 in all the views How can I do that ?

Any help is highly appreciated.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • 5
    Hint: `alter view`. One at a time. – Gordon Linoff Jun 18 '19 at 14:22
  • 1
    Are your views fed from an underlying table which has been altered? – jimmy8ball Jun 18 '19 at 14:25
  • Use Excel or unix (awk, etc.) to generate the script to save you time. – Jose Manuel Gomez Alvarez Jun 18 '19 at 14:25
  • If your views are indeed looking at altered tables i.e. using a select * from YourTable definition, then you could alter each table using a script, and then recompile the affected views by using the sp_recompile – jimmy8ball Jun 18 '19 at 14:27
  • 2
    `alter view` does not works like `alter table` You need to write the entire view again and then add your new column. Look at [this](https://stackoverflow.com/questions/39535278/how-to-add-new-column-in-existing-view-in-sql-server-2014-using-alter/39535322#39535322). So its not going to be easy to generate something for that – GuidoG Jun 18 '19 at 14:30

0 Answers0