Introduction:
Description:
In
previous posts I explained difference between wcf and web
application,
interview questions in asp.net, sql
server, c#,
Difference between functions and stored
procedures in SQL Server, difference between len and datalength
in sql server
and many articles relating to SQL
Server.
Now I will explain the differences between SQL view and stored
procedures.
View in SQL Server
A view represents a virtual table. By using view we can
join multiple tables and present the data as coming from a single table.
For
example consider we have two tables
1) UserInformation table with columns userid, username
2) SalaryInformation table with columns salid, userid, salary
Create
VIEW by joining above two tables
CREATE VIEW
VW_UserInfo
AS
BEGIN
SELECT a.userid,a.username,b.salary from UserInformation a INNER
JOIN SalaryInformation b ON a.userid=b.userid
END
|
By
using above view we can get username or salary based on userid for that we need
to create procedure like as shown below
CREATE PROCEDURE
GetUserInfo
@uid INT
AS
BEGIN
SELECT username from
VW_UserInfo WHERE userid=@uid
END
|
If
you observe above procedure it’s like getting username from single table (VW_UserInfo)
by passing userid
Stored
Procedure
A
stored procedure is a group of sql statements that has been created and stored
in the database. Stored procedure will accept input parameters so that a single
procedure can be used over the network by several clients using different input
data. Stored procedure will reduce network traffic and increase the
performance. If we modify stored procedure all the clients will get the updated
stored procedure
USE
AdventureWorks2008R2;
GO
CREATE PROCEDURE dbo.sp_who
AS
SELECT FirstName, LastName FROM
Person.Person;
GO
EXEC sp_who;
EXEC dbo.sp_who;
GO
DROP PROCEDURE dbo.sp_who;
GO
|
For more information check this Stored procedure in SQL Server
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
13 comments :
nice article
Article is very nice.
Txn
not clearly explained
not clear
good very nice job..........
You provide us great oppertunity to learn new and good concept
sir please write an article about sql transactions
You didn't explain about differences.....
not clear ...cloud you please explain some more detail
In this website every article is explained in very neat manner. The article and concept is very nice.
In this Website All Articles very nice.
Good Articles
Pls given More detail..you not tell the differences
Note: Only a member of this blog may post a comment.