sql - What is the difference between a stored procedure and a view? -


i confused few points:

  1. what difference between stored procedure , view?

  2. when should use stored procedures, , when should use views, in sql server?

  3. do views allow creation of dynamic queries can pass parameters?

  4. which 1 fastest, , on basis 1 faster other?

  5. do views or stored procedures allocate memory permanently?

  6. what mean if says views create virtual table, while procedures create materials table?

please let me know more points, if there any.

a view represents virtual table. can join multiple tables in view , use view present data if data coming single table.

a stored procedure uses parameters function... whether updating , inserting data, or returning single values or data sets.

creating views , stored procedures - has information microsoft when , why use each.

say have 2 tables:

tbl_user columns: .user_id, .user_name, .user_pw

tbl_profile columns: .profile_id, .user_id .profile_description

so if find myself querying tables alot... instead of doing join in every peice of sql define view like:

create view vw_user_profile   select a.user_id, b.profile_description   tbl_user left join tbl_profile b on a.user_id = b.user_id go 

so in future if want query profile_description user id... have is

select profile_description vw_user_profile user_id = @id 

that code used in stored procedure like:

create procedure dbo.getdesc  @id int begin select profile_description vw_user_profile user_id = @id end go 

so later on can call

dbo.getdesc 25 

and description user id 25. 25 parameter.

there lot more detail, but, basic idea.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -