Using views instead of tables in stored procedures?

Is it good to process views instead of source tables in stored procedures? (even if the view does not provide any different data)

I always thought this might be a good idea because it is an extra layer of abstraction and its similarity using properties instead of member variables in class functions.

But now I looked at the stored procedures created by the ASP.NET membership provider, and they always query tables directly.

I know that you cannot easily insert data when using views, but if the stored procedure only requests data if you use tables directly anyway? If so, what is the main reason? (Performance?)

+3
source share
4 answers

A view is just a macro that expands into an external request.

If your view contains several joins, then when you join other views, you suddenly have 20 or 30 JOIN methods, when you really see 3 JOINs in the SQL stored procedure. You will also find that each query is different: why continue to join the same 20 or 30 tables for each query?

As a rule, there is no benefit if the view is not indexed / materialized and the optimizer can use it.

, , , : ? .

( ).

, (, SUSER_SNAME),

+6

-, . , , ( ), .

Sql Server, where, :

  • NULL
  • LIKE '% something'

, , , .

, sarg. ( Sql Server) - 5 .

, "" , , , . , -.

Sql Execution Plan for accessing a simple view compared to the table directly

+3

:

1 - ,

2 - . , , "member" "non_member". . , - , "member" "non_member", "user" . , , . , .

0

SQL Server ( ) , , , , . , , , SPRC , , .

, ? , , , , , , .

, , , , . SPROC INSERTS UPDATES, .

, , ( ), , ( ) , , CODING (, - , , SPROC ?).

SPROC, .,.

0

Source: https://habr.com/ru/post/1790197/


All Articles