In this article I am going to describe about VIEW in SQL Server 2005. Though this is a simple topic, still I am writing This is not only about view, I have made some plan to write a few article on SQL Server 2005. I hope this will also help you like my ASP.NET articles. Please give me your valuable suggestion and feedback to improve my articles.

What is VIEW
A view is an "Virtual Table". It is not like a simple table, this is an virtual table which contains columns and data from different table ( may be one or more tables) . View does not contain any data directly, it is a set of query that are applied to one or more tables that is stored within the database as object. After creating a view from some Table, it just used as a reference of those table and when executed shows only those data which are already mention in query during the creation of View

In the above diagram, we have created a View (View_Table1_Table2) from Table1 and Table2. So the View_Table1_Table2 will show only the information of those columns. Let's checkout the basic syntax for creating a view: Collapse
CREATE VIEW [View Name] AS [SELECT Statement]

Use of VIEW

So rest data are totally abstract from the end user. It having on table called EmpInfo and below diagram showing you the design of the table. Creating a View Below is the general syntax for creating a view Collapse CREATE VIEW [View_Name] AS [SELECT Statement] As for example Collapse CREATE VIEW SampleView As SELECT EmpID. that will only contain EmpID. Because it restricts user to view certain column and Rows. select data from view and deleting a view. Along with Security the other advantages of view is Data abstraction. Views display only those data which are mentioned in the query. which contain following data Here all the example I have descrived only from this database.Views are used as Security Mechanism of Database. so its shows only those data which returns by the query that is defined at the time of creation of view. Because end user is not aware of all the data in Table. General Syntax for View In this section I have described how to create view. EmpName FROM EmpInfo Which will create a view with name "SampleView". EMPName. ViewDemo. I have create on Database named. .

Get Result From View This is as similar as select statement of a table Collapse select * from SampleView Now have a look on the output of the SampleView Drop a View Collapse DROP VIEW SampleView Now if we want to select the data from the sampleview. we will get following error Different Types of VIEW There are two different types of VIEW   System View o Information Schema View o Catalog View o Dynamic Management View(DMV) User Define View o Simple View o Complex View Now just have a look on different types of View in SQL Server 2005. System View .

Each and . Expand any Database > View > System View In SQL Server all system view are divided into different schema. This are used for displaying most physical information of a database. These are also used as template View for all new database. There are twenty different schema views in this group. So I will not going to Details of It. like Master. We can categorized system view in following way. System Views are predefined Microsoft created views that are already existed in master DB. Lets have a look into the over view of those view type Information View These are the one of the most important system grouped view. These are used for the security container of SQL Server database.    Information Schema View Catalog View Dynamic Management View (DMV) Now all above category are itself a huge topic. Temp. tempdb . such as .In SQL Server there are few System Database available. like master data is one of the template database for all the database which are created in SQL Server 2005. These System Views will be automatically inserted into any user created database. We can explore the System view from the SQL Server Management Studio. Similarly. Each and every data base having its own responsibility. There are around 230 System view available. msdb.

Now. Catalog View This type of view are introduced in SQL Server 2005. columns.table. It having on table called EmpInfo and below diagram showing you the design of the table. catalog view are categorized in different group also.[View Name] . Collapse select * from sys. As for example. Lets see it with one Example.tables . These are used to show the database self describing information. if we want to know the details information columns of table Empinfo using View we have to run the following query. ViewDemo. Naming Conation of this type of views are INFORMATION_SCHEMA. Collapse SELECT * FROM INFORMATION_SCHEMA. From the System View Image we can get the few name of Information Schema View.COLUMNS Where TABLE_NAME='EmpInfo' Following will be the output Similarly we can use all other Schema View to read Database information. I have create on Database named.

This views are created by the user as per requirement. Now we can again have a look into another view creation. auth_scheme FROM sys.client_net_address.A SQL Server 2005 Feature [^] Note: There are many things to learn on System View.dm_exec_connections And following is the sample output If you want to know details on DMV. Server-scoped DMV: Stored in Master Database 2. There is no such classification of UDV and how to create the view. there are two types of DMV 1.This Views gives the database administrator information about the current state of the SQL Server machine. These values will help the administrator to diagnose problems and tune the server for optimal performance. Here is an Complete article on Code project . Database-scoped DMV: Specific to each database As for example if we want to check the all SQL Server connection. session_id. If any one having more interest can have a look into this article System Views in SQL Server 2005 [^] User Define View Still now I have described about System View. In SQL Server 2005. Collapse . Now have a look into User Define View.and following is the sample output Dynamic Management View This is newly introduced in SQL Server 2005. Collapse SELECT connection_id. we have to use following query. I have just introduced them for beginners . I have already explained the syntax. Dynamic Management Views [DMV] .

FROM DBO.[DbName] . while specifying the Database name we have use Dbo. If we want to change/Alter the defination of a table which refered by a schema binded view.   Schema Binding Option Encryption Schema BindSchema Binding Option : If we Creates a view with the SCHEMABINDING option it will locks the tables being referred by the view and restrict any kinds of changes that may change the table schema ( No Alter Command) . EmpName. we will get following error message. While creating schema binding view. . We have to mention all the column name for reference As for example. EmpName. Collapse CREATE VIEW DemoSampleView With SCHEMABINDING As SELECT EmpID. 2.EmpInfo And one more things that we need to remember. we cannot do it! This is the power of the SCHEMABINDING option. Phone FROM EmpInfFROM EmpInfo When To Use A View There are a number of scenarios where we will like to create our own view 1. To control access to rows and columns of data. or customize the data and schema for a set of users. To hide the complexity of the underlying database schema. we can't mention "Select * from tablename" with the query.CREATE VIEW DemoView AS SELECT EmpID. try to alter the table EmpInfo .After creating the view. View Creation Option There are two different option for creating a view.

there is no way to decrypt it again. Now. . Syntax for creating view and all other stuff I have already covered.EmpInfo Note: Once view is encrypted. Use SSMS for Create View studio provided handy GUI for creating and managing the View.Encryption : This option encrypts the definitionThis option encrypts the definition of the view. This is the main adavatages of view where we can make it secure Collapse CREATE VIEW DemoView With ENCRYPTION. Users will not be able to see the definition of the View after it is created. SQL Server MSQL Server Management First just expand da ViewDemoDB > Move to View . In this section we will just quickly check how SSMS used to create a maintain view. Right Click on View Folder. What is view. In Object Explorer Tab. it listed all the View with corresponding to its database.

In the ViewDemoDB we are having two data tables. Now am going to create View from EmpInfo Table Select the EmpInfo. You will redirected to Create View Screen where you can configure the view creation. Following Screen will come . . Check the following image. Click on Add.When we will click on the New view .

. Give the name of View and click on Ok. where we can select the table name or in below section.Above image showing three section. When its done. we can right query for view also. Now again go to ViewDemoDB > View > Expand View folder. Just click on Save button on toolbar. Here along with system view you can see the view that we are created right now.

If we right click on it.So. this is our user define View. we will get the option of open the view and which will show the result of View. We can also create a view from a view itself as similar way that we already done with tabl .