+ 4
What does Stored Procedures and views mean?
Hey, I just started learning SQL here and in the definition I came across a line that said 'SQL can create stored procedures and views'. Can anyone tell me what do Stored procedures and views mean? thanks
4 Answers
+ 16
Hey!
1. View: A view is a virtual table based on the result-set of an SQL statement.
A view contains rows and columns, just like a real table.
2. Stored procedure: A stored procedure is a set of SQL commands like INSERT, UPDATE, DELETE, DROP... It's pretty useful for automation for example.
+ 1
Thank you for the answer :) r8w9
+ 1
Stored procedure is a compiled file of set of instructions supported by sql.(it has a lot of advantages than function)
View is just a compiled file of a select query only. To make your select query faster we prefer to create view.
+ 1
A view will still return 1 data set, similar to a table, but can be made up of many underlying sources. For example, a view can return fields from 1 source, or many sources.
Create View Example:
create view view_name as
select a.column1, b.column2
from table_name as a
left join table_name as b on a.primary_key = b.primary_key
The select statement for a view is the same as a table:
Table Example:
Select *
From Table
View Example:
Select *
From View
Stored Procedures can automate tasks. For example, a stored procedure can run daily and can load SQL Tables. Procedures can be run by daily "Jobs" and can be set to run based on data driven requirements, or at a certain time.
So for example:
1) A procedure is built and set to execute at 5am and load a table
2) At 5am procedure executes and loads table
3) Table is now loaded with yesterdays data
4) A view is queried at 7am that references that table
5) The view returns updated data since the underlying table is updated