Difference B/w View and Query

  • I had created following table

    Create Table emp(empid int,ename varchar(30))

    Insert Into emp values(101,'A')

    Insert Into emp values(102,'B')

    Insert Into emp values(103,'C')

    and I had created following view on emp table

    Create View Vw_EmpDet

    as

    Select empid,ename from emp

    Then what is the difference b/w following two statements

    first one is

    Select empid,ename from emp

    second one is

    Select empid,ename from Vw_EmpDet

  • Well, there should be no difference between the results from what I can see. What problem are you having?

    The view is redundant however...

    The view may perform marginally worse as the second query effectively becomes:

    Select empid,ename from (Select empid,ename from emp) Vw_EmpDet

    But I would imagine the query optimiser will pick the same execution plan for both

  • satishthota (9/15/2009)


    I had created following table

    Create Table emp(empid int,ename varchar(30))

    Insert Into emp values(101,'A')

    Insert Into emp values(102,'B')

    Insert Into emp values(103,'C')

    and I had created following view on emp table

    Create View Vw_EmpDet

    as

    Select empid,ename from emp

    Then what is the difference b/w following two statements

    first one is

    Select empid,ename from emp

    second one is

    Select empid,ename from Vw_EmpDet

    The only difference will be the extra check for auth to use the view.

    Another difference is that using the view, you can only select/update columns that are available in the view definition.

    Via the view, you can also prevent updates that would result in rows nolonger qualifying for the view.

    ( check BOL "Create view" WITH CHECK OPTION )

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply