Views can provide a different representation (such as subsets or supersets) of the data that resides within other tables and views.Views are very powerful because they allow you to tailor the presentation of data to different types of users.You can use views in almost the same way as tables.You can query, update, insert into, and delete from views, just as you can standard tables.SQL Server views can get really weird when an underlying table is updated.I’ll show some examples and also the one must do for views to avoid problems.You can think of a view as a lens looking at one or more tables.A view is really nothing more than a logical representation of one or more tables in a database.
Right-click the SQL Server Logs node and select View, then select SQL Server and Windows Log from the context menu.
The broken views problem is something I discovered when working on a production system. When I dug deeper into it I was even more shocked at the pure evilness this behaviour could cause.
But let’s take it from the start with a simple table of colours and a view on top of it to start with.
CREATE TABLE [dbo].[Colours] ( [Id] INT IDENTITY (1, 1) NOT NULL, [Colour] NVARCHAR (10) NOT NULL, CONSTRAINT [PK_Colours] PRIMARY KEY CLUSTERED ([Id] ASC) ); GO CREATE VIEW [dbo].[Bad View] AS SELECT * FROM Colours.
That would be good – if it contained the right data. The data is taken from the second column of the underlying table. The database is not just showing some really weird behaviour.
The column names in an expanded column list are enclosed in quote marks to account for the possibility that the columns of the base object were originally entered with quotes and require them for the query to be syntactically correct.