VB.net Refreshing SQL Views when new columns are added to a table


I have a SQL database that has multiple Views. When I add a new column into one of the tables used in these views this doesn't automatically refresh the Views. I have to go and manually recreate them. Having posed the question on whether this can be refreshed automatically I received a "no" as the answer. I  want to write VB.net code to do this. I need help with the best way to go about this.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
Pawan KumarConnect With a Mentor Database ExpertCommented:
Yes if you want to do that in VB.NEt then call a SP and inside that use below. It will work.

EXECUTE sp_refreshview N'YourViewName';
Pawan KumarDatabase ExpertCommented:
When you add a column or delete a column from the table and if your view uses * in the column list then use below command to update the view. You can easily do this in the SQL itself. Dont write the VB.NEt code. Try below once!!

ALTER TABLE yourtableName	
  ADD column_name INT;

EXECUTE sp_refreshview N'YourViewName'; 

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks. I have to do this in VB.net because it is for the users of my app. Surely there is a way to do exactly what you are doing via VB.net
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much. I appreciate the help
Éric MoreauSenior .Net ConsultantCommented:
buy using select * is not considered a best practice!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.