Solved

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

Posted on 2016-10-15
5
39 Views
Last Modified: 2016-10-15
Hi

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.
0
Comment
Question by:murbro
  • 2
  • 2
5 Comments
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41844881
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

0
 

Author Comment

by:murbro
ID: 41844883
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
0
 
LVL 28

Accepted Solution

by:
Pawan Kumar earned 500 total points
ID: 41844885
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';
0
 

Author Closing Comment

by:murbro
ID: 41844887
Thanks very much. I appreciate the help
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41844976
buy using select * is not considered a best practice!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question