SQL Server Interview Questions and Answers Part 8

By
1.) What is view in SQL Server ?                                                                                               
A View is a logical or virtual table,which does not exists physically in the database.View is an object which contains 'select' statement.View is consider like as Virtual table.

2.) What are the main purpose to create a view ?                                                               
We create views for two main purpose.
  1. To make complex query to simple query
  2. Database Security .
3.) Why we create view in sql server or other explain?                                                     
There is following reason to create a view in sql server or other database.
  •  If we don't want to show all the column's data of the table to an user then we generally create a view.
4.) How to create a view in sql server explain?                                                                     
Suppose we have two table studentdetails and scourse then we create view as given below:-
create view vdata(student_id,student_name,student_course)
as
select sid,sname,cname from scourse c  join studentdetails s

on c.id=s.sid

5.) How to create a view with left outer join concepts?                                                     
create view vdata1(student_id,student_name,student_course)
as
select sid,sname,cname from scourse c  Left join studentdetails s
on c.id=s.sid


6.) How to create a view with Right outer join concepts ?                                               
create view vdata2(student_id,student_name,student_course)
as
select sid,sname,cname from scourse c  Right join studentdetails s
on c.id=s.sid


7.) How to create a view with full outer join concepts ?                                                 
create view vdata3(student_id,student_name,student_course)
as
select sid,sname,cname from scourse c  full outer join
studentdetails s on c.id=s.sid


8.) How to get data from a view?                                                                                               
Syntax:-
select *from view_name
Ex. 
select*from vdata

9.) How to get the view details in database?                                                                          
sp_help vdata
sp_helptext vdata

10.) How to delete view from database?                                                                                  
Drop view vdata

11.) What are the main conditions to insert,delete and update the records  within table with view ?  
There are two main conditions as given below:-
  1. View must contain only one table within select query(no join tables).
  2. Select query in view must contain all not nullable columns.

0 comments:

Post a comment

Powered by Blogger.