Wednesday, 18 July 2018

SQL Server View

 
View is a nothing but a virtual table. View is a query statement on database using one or multiple tables .View does not store physical data , view fully virtual.
         Changes in any table used for view , data of view automatically changes. You can get data from view ,you can join view with tables, but you can not modify data of a view.View widely used for reporting purpose.  

You can use view in a function , store procedure to get arranged data quickly.

          You can create a view in two ways  

A)By interface  
B)Writing script. 

Interface and script both allowed to create ,update ,delete view.

           Here we are going to learn how a view can be created using interface.From SQL management Studio 

Create View By Interface 
 
1)Do login.





2)Select database.

3)Go to the view and right click, you will get context menu called "New View".



4)Click on "New View" , an interface will be open showing the list of tables you can use. 



5)Then close the Tables. You will see graphical interface of table will created and you can click on columns to make relation and by selection of tables. 



6)In the lower portion , you will see that automatic sql query have been prepared while selecting the columns.Click on "Save" , an confirmation window will as the name of the View , click OK.






You can create view by writing script also. 

Create View By script 

1)Go to Management Studio 

2)Open a new query window write a script for create view and press F5.

CREATE VIEW vw_student
AS SELECT a.name,
                a.date_of_birth, 
                b.height
          FROM student a inner join
                    student2 b on a.id=b.id


Below is the syntax for creating a view

CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition; 


You can also delete view from both interface and script. 


To Delete a view from Interface

1)Open SQL server management Studio and login, select views you want to delete, click on delete.

2)An interface will open for confirmation of delete, click on "Ok".


 
To Delete a view from script

1)Go to Management Studio 

2)Open a new query window write a script for delete view and press  F5.

DROP VIEW vw_student

No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...