Solved

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

Posted on 2016-10-15
5
58 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 29

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:Murray Brown
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 29

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:Murray Brown
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

617 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