SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Why does view not refresh when column inserted.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bogey
Posting Yak Master

166 Posts

Posted - 06/25/2008 :  08:32:12  Show Profile  Reply with Quote
A colleague of mine ran into a problem today. He had a view on a Table called employee that was this "select * from employee". He then altered the table and inserted a column in the 2nd position with default values. Now when he runs the view its not showing the new column but it is showing the data in the orginal 2nd column. I'm assuming that its not best practice to insert columns into existing tables but they should be added to the end of the table. Anyone know why this works like it does?

thanks.

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/25/2008 :  08:36:52  Show Profile  Reply with Quote
Its not a good practise to use select * in views. If you use it you need to ensure whenever the table structure changes, you drop and recreate view to reflect the new structure.
Go to Top of Page

bogey
Posting Yak Master

166 Posts

Posted - 06/25/2008 :  08:41:07  Show Profile  Reply with Quote
quote:
Originally posted by visakh16

Its not a good practise to use select * in views. If you use it you need to ensure whenever the table structure changes, you drop and recreate view to reflect the new structure.



Should not an alter force recompilation of all objects that depend on the altered object?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/25/2008 :  08:56:26  Show Profile  Reply with Quote
quote:
Originally posted by bogey

quote:
Originally posted by visakh16

Its not a good practise to use select * in views. If you use it you need to ensure whenever the table structure changes, you drop and recreate view to reflect the new structure.



Should not an alter force recompilation of all objects that depend on the altered object?


Alter will only alter the structure of table alone not dependent views. You need to recreate the view once tables have changed. thats what bol also suggests:-

If a view depends on a table (or view) that has been dropped, SQL Server produces an error message if anyone tries to use the view. If a new table (or view) is created, even if 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 re-created.
Go to Top of Page

mdubey
Posting Yak Master

USA
133 Posts

Posted - 06/25/2008 :  09:40:37  Show Profile  Reply with Quote
View is dependant on the Table(Source). Whenever any changes happen in the Table(Source) you need to recreate a view if required.(If you wanted to modify view). It will not take automatically effect on the view.

Manoj
MCP, MCTS
Go to Top of Page

rmiao
Flowing Fount of Yak Knowledge

USA
7266 Posts

Posted - 06/28/2008 :  22:14:56  Show Profile  Reply with Quote
You can refresh view with sp_refreshview.
Go to Top of Page

maninder
Posting Yak Master

USA
100 Posts

Posted - 06/29/2008 :  18:54:30  Show Profile  Send maninder a Yahoo! Message  Reply with Quote
Inserting COLUMNS Does not change Their ORDINAL Positions, they will be added as the last Column(s), Unless, you goto DESIGN View and INSERT a Column at a relevant position, this will show you the column at that Position.
This will however not refresh the view. To Refresh teh View, you have to alter the View to Refresh the list.
ALTER VIEW ViewName
AS
select * from employee

Maninder
Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 06/29/2008 :  21:41:32  Show Profile  Reply with Quote
quote:
Originally posted by rmiao

You can refresh view with sp_refreshview.



Rmaio is correct too.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000