﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Steve Jones / Article Discussions / Article Discussions by Author  / Views and changes / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 01:18:43 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>I took the schema change part of the question to mean that the schema to which the table belonged changed, e.g. from 'dbo' to 'Person' in which case the correct answer is to drop and recreate the view. :angry:</description><pubDate>Fri, 24 Aug 2012 09:33:33 GMT</pubDate><dc:creator>Lempster</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Nice question.But referencing an Sql 2005 BoL page seems a bit odd, as SQL 2005 is out of support (even though the same SP is still there now).</description><pubDate>Fri, 20 Jul 2012 11:31:09 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>[quote][b]GPO (7/5/2012)[/b][hr]I wonder whether all SELECT * in views are created equal. That is to say equally evil. For example is a SELECT* from a preceding  CTE just as bad as select * from a base table? I would have thought that selecting from the CTE was a lesser evil because everything the * is dependent on is encapsulated within the view and therefore can't be broken by a change to the underlying objects.Not advocating anything, merely wondering;-)[/quote]SELECT * in the final select (that defines the result set of the view) is always wrong.SELECT * in subqueries or CTEs is not always bad, though I personally try to avoid it.</description><pubDate>Thu, 05 Jul 2012 13:34:28 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>I wonder whether all SELECT * in views are created equal. That is to say equally evil. For example is a SELECT* from a preceding  CTE just as bad as select * from a base table? I would have thought that selecting from the CTE was a lesser evil because everything the * is dependent on is encapsulated within the view and therefore can't be broken by a change to the underlying objects.Not advocating anything, merely wondering;-)</description><pubDate>Thu, 05 Jul 2012 13:12:05 GMT</pubDate><dc:creator>GPO</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>[quote][b]Andrew Diniz (7/3/2012)[/b][hr]On a serious note, where is a view's meta-data kept and under what circumstances might a view return inconsistent results as a result of base table schema changes?[/quote]The metadata is stored in internal tables that you cannot access directly. You can access them through several object management views, including sys.objects, and sys.views for the view itself, sys.columns for the columns defined in a view, and sys.sql_modules for the definition.Here is one of many possible ways to demonstrate inconsistent results after base table schema changes:[code="sql"]CREATE TABLE dbo.MyTab (IntCol int, CharCol char(1));INSERT INTO dbo.MyTab (IntCol, CharCol) VALUES(1, 'a');goCREATE VIEW dbo.MyViewAS SELECT * FROM MyTab;goSELECT * FROM dbo.MyView;goALTER TABLE dbo.MyTab DROP COLUMN IntCol;ALTER TABLE dbo.MyTab ADD NumCol numeric(5,3);goUPDATE dbo.MyTab SET NumCol = 1;goSELECT * FROM dbo.MyView;goDROP VIEW dbo.MyView;DROP TABLE dbo.MyTab;go[/code]</description><pubDate>Tue, 03 Jul 2012 04:10:42 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Indeed. And depending on how you interpret "ensure the view returns the [b]correct[/b] results", you may have to alter the view. The 'correct' results may be those which have no impact downstream and therefore do not pick up changes to the base table(s) :hehe: On a serious note, where is a view's meta-data kept and under what circumstances might a view return inconsistent results as a result of base table schema changes?</description><pubDate>Tue, 03 Jul 2012 03:54:51 GMT</pubDate><dc:creator>Andrew Diniz</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>[quote][b]Hugo Kornelis (7/3/2012)[/b][hr]It's a bit disappointing that nobody has yet commented that the "best" way to deal with the issue is to drop the view, then create a new one that does not use SELECT * but spells out the relevant columns. :-DNice question, Steve. Thanks![/quote]Would not an ALTER VIEW with a proper column list also suffice? No need to reassign permissions afterwards too.A few people's posts have implicitly said they'd do a column list in place of SELECT * :-D</description><pubDate>Tue, 03 Jul 2012 02:59:09 GMT</pubDate><dc:creator>Gazareth</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>It's a bit disappointing that nobody has yet commented that the "best" way to deal with the issue is to drop the view, then create a new one that does not use SELECT * but spells out the relevant columns. :-DNice question, Steve. Thanks!</description><pubDate>Tue, 03 Jul 2012 01:12:26 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Thanks Steve for the easy one !!!!</description><pubDate>Mon, 02 Jul 2012 21:53:18 GMT</pubDate><dc:creator>baabhu</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>A nice one to start the week. Thanks, Steve!</description><pubDate>Mon, 02 Jul 2012 16:39:10 GMT</pubDate><dc:creator>Revenant</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>[quote][b]sknox (7/2/2012)[/b][hr][quote][b]Bob Razumich (7/2/2012)[/b][hr]For a moment, I thought the correct answer was a trick answer. "sp_refreshview"? It just seemed too cute for a Monday, but I looked it up first, anyway...[/quote]+1I figured the first answer was wrong because DROP...CREATE VIEW is not the only way to fix that problem, even without the existence of sp_refreshview. You can also use an ALTER VIEW statement. Since the third answer was patently untrue as well, whatever remained, however improbable, had to be true. That's how I deduced that there was, indeed, a stored procedure called sp_refreshview.[/quote]Awesome deduction! Much more entertaining than the method I used.</description><pubDate>Mon, 02 Jul 2012 11:54:45 GMT</pubDate><dc:creator>Bob Razumich</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>[quote][b]Bob Razumich (7/2/2012)[/b][hr]For a moment, I thought the correct answer was a trick answer. "sp_refreshview"? It just seemed too cute for a Monday, but I looked it up first, anyway...[/quote]+1I figured the first answer was wrong because DROP...CREATE VIEW is not the only way to fix that problem, even without the existence of sp_refreshview. You can also use an ALTER VIEW statement. Since the third answer was patently untrue as well, whatever remained, however improbable, had to be true. That's how I deduced that there was, indeed, a stored procedure called sp_refreshview.</description><pubDate>Mon, 02 Jul 2012 11:34:57 GMT</pubDate><dc:creator>sknox</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>[quote][b]steve.casey (7/2/2012)[/b][hr]Some of us have to work with versions older than SS 2005, you know!  DROP...CREATE is the only one that will work with ALL versions.[/quote]That's what I thought too... of course I don't write many views.... tables yes... stored procs yes...... views.... rarely.That said, I had to find out what the heck sp_refreshview was if it existed... and it changed my answer.  :)Yay +1</description><pubDate>Mon, 02 Jul 2012 10:07:39 GMT</pubDate><dc:creator>mtassin</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>EZ PZ</description><pubDate>Mon, 02 Jul 2012 09:36:22 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Thanks for the easy one Steve! I think I have used this command maybe once before.</description><pubDate>Mon, 02 Jul 2012 08:49:08 GMT</pubDate><dc:creator>KWymore</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Great easy question this morning Steve. Thanks for that pick me up on Monday. :-)</description><pubDate>Mon, 02 Jul 2012 07:12:40 GMT</pubDate><dc:creator>Dana Medley</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>[quote][b]Bob Razumich (7/2/2012)[/b][hr]For a moment, I thought the correct answer was a trick answer. "sp_refreshview"? It just seemed too cute for a Monday, but I looked it up first, anyway. Plus, I'd be strung up if I created a view as Select * from anything. Glad I researched it. But I have to say that the command would seem to enable poor coding practice in creating a view, IMHO.[/quote]It's like Bob was reading my mind! (Except for the fact that he wrote this BEFORE I saw the question. How DO you do that Bob?)So, +1, and thanks for a great question for a Monday Steve.</description><pubDate>Mon, 02 Jul 2012 06:31:38 GMT</pubDate><dc:creator>Thomas Abraham</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>For a moment, I thought the correct answer was a trick answer. "sp_refreshview"? It just seemed too cute for a Monday, but I looked it up first, anyway. Plus, I'd be strung up if I created a view as Select * from anything. Glad I researched it. But I have to say that the command would seem to enable poor coding practice in creating a view, IMHO.</description><pubDate>Mon, 02 Jul 2012 06:13:29 GMT</pubDate><dc:creator>Bob Razumich</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Learnt something this morning so thanks for a good start to the week.:-D</description><pubDate>Mon, 02 Jul 2012 04:41:35 GMT</pubDate><dc:creator>skanker</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>I always learn something new at SQLSeverCentral!!! :-)Thanks guys!!!</description><pubDate>Mon, 02 Jul 2012 03:32:55 GMT</pubDate><dc:creator>Mr Quillz</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Some of us have to work with versions older than SS 2005, you know!  DROP...CREATE is the only one that will work with ALL versions.</description><pubDate>Mon, 02 Jul 2012 03:32:16 GMT</pubDate><dc:creator>steve.casey</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Read the question as "with schemabinding", grumble.Serves me right for not having a coffee yet! :doze:</description><pubDate>Mon, 02 Jul 2012 02:30:15 GMT</pubDate><dc:creator>Gazareth</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Good question - made me think for a bit (I never use SELECT * in views, of course ;-) )</description><pubDate>Mon, 02 Jul 2012 01:34:48 GMT</pubDate><dc:creator>Duncan Pryde</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Thanks for the QOTD Steve.</description><pubDate>Mon, 02 Jul 2012 01:27:46 GMT</pubDate><dc:creator>paul s-306273</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Easy one for a Monday, thanks Steve!</description><pubDate>Mon, 02 Jul 2012 01:12:04 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Thank you Steve, easy start for the week :-)</description><pubDate>Sun, 01 Jul 2012 09:31:18 GMT</pubDate><dc:creator>mohammed moinudheen</dc:creator></item><item><title>Views and changes</title><link>http://www.sqlservercentral.com/Forums/Topic1323556-32-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/91144/"&gt;Views and changes&lt;/A&gt;[/B]</description><pubDate>Sun, 01 Jul 2012 09:30:48 GMT</pubDate><dc:creator>Steve Jones - SSC Editor</dc:creator></item></channel></rss>