Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You shouldn't be needing that.</p> <p>If you are concerned about differences of your views and your underlying tables, then you should schemabind your views. That way your table can't be modified in the way it clashes with view definition. In addition, you can't use <code>SELECT *</code> in a schemabound view.</p> <p>However, if you want to play with automatic view refreshing, here's the idea:</p> <pre><code>CREATE VIEW tv AS SELECT * FROM dbo.t1 UNION ALL SELECT * FROM dbo.t2 GO CREATE TRIGGER alterView ON DATABASE FOR ALTER_TABLE AS EXEC sp_refreshview 'tv' GO ALTER TABLE dbo.t1 ADD txt nvarchar(18) ALTER TABLE dbo.t2 ADD txt nvarchar(18) </code></pre> <p>However, you will notice that it's not possible to do alter in the first place, because it would break the 'equal number of expressions' rule for the view.</p> <p><em>EDIT</em></p> <p>I could have missed the point because I maybe didn't understand the question. If you want to alias, you can use <a href="http://technet.microsoft.com/en-us/library/ms177544.aspx" rel="nofollow">SYNONYMS</a>. If combined with schema, you can use them to alias a view:</p> <pre><code>CREATE SCHEMA TEST GO CREATE SYNONYM TEST.t1 FOR dbo.tv GO SELECT * FROM TEST.t1 GO </code></pre> <p>If your focus is on the syntax, you will notice that new t1 aliased view is prefixed woth the schema. However, if you wrap that with procedure, you can loose the prefix and data will be selected from your aliased view.</p> <pre><code>CREATE PROCEDURE TEST.TestProc AS SELECT * FROM t1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload