How To Create View In SQL Server, the Easy Way Create

We know about the ultimate Visual Interface Microsoft’s SQL Server has and today I will discus about using this Visual Interface to create Views an easy way. Views are the virtual tables, and data in them is not actually reside in your hard drive corresponding to your View. The data is just a mirror image from one or more Table which may even belong to different database. You can select all or less columns from the selected tables, to show all the content from all the selected columns as a data from single View. Your tables should be Normalised if you want to taste the best use of Views. If your database is not normalised, then your View will be having a lot of repeated data, of no use.
To illustrate the steps I will be using SQL Server 2008 R2 and AdventureWorks database.
Instructions:
  1. Expand your database in SQL Server Object Explorer.
  2. Right click on Views and select New View.
    image thumb20 How To Create View In SQL Server, the Easy Way
  3. In the New View dialogue, you can select the table you want to include for your view and then click Add button to add that table. Even you can select already existing Views to with table to get data from tables and Views in a single View.
  4. After adding all the required tables, close the dialogue and you will see all the selected tables appeared on the screen showing all the tables and relation between all the tables.
  5. SQL Server will create all the Joins required to filter the data in proper way according to the relations your tables have.
  6. Now just check all the columns you want to have in your View.
    image thumb21 How To Create View In SQL Server, the Easy Way
  7. In the 2nd panel where all the selected columns got listed, you can create additional filters to get filtered data. You can specify the sorting order for a column either Ascending or Descending, you can specify the limit on a column to get some portion of data not all by specifying the Filters with ‘>’, ‘<’, ‘=’ signs followed by the filter. Just have a look at the following image for clear view.
    image thumb22 How To Create View In SQL Server, the Easy Way
  8. When done, just press Ctrl + S to save the view with a specified name.
    image thumb23 How To Create View In SQL Server, the Easy Way
  9. After this you can select data from this view the same way you select data from a normal tabl
  10. image thumb24 How To Create View In SQL Server, the Easy Way 

0 comments:

Post a Comment