What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 13957 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > SQL Server Interview Questions > Define Stored Procedure with Example? .. ...

Define Stored Procedure with Example?

Interview question and answer by: Sriramnandha | Posted on: 6/4/2012 | Category: SQL Server Interview questions | Views: 1153 | | Points: 40


Answer:

Stored Procedure is an collection SQL Statements. To Reuse the code over and over again.
Stored Procedure is an Precompiled Execution. Stored Procedure have input and out put Parameters.
Stored Procedure Can reduce the Client /Server Network Traffic.
Explanation:
Before Creating store procedure whether insert data or select data..
In This example am using Adventure works DataBase

SELECT * FROM AdventureWorks.Person.Address


CREATE PROCEDURE GetAddress
AS
SELECT * FROM AdventureWorks.Person.Address
GO


EXEC GetAddress

--or just simply
uspGetAddress


To Create a Stored Procedure u can use Create Procedure or Create Proc
Just like you have the ability to use parameters with your SQL code you can also setup your stored procedures to except one or more parameter values.

CREATE PROCEDURE uspGetAddress @City nvarchar(30)

AS
SELECT *
FROM AdventureWorks.Person.Address
WHERE City = @City
GO


CREATE PROCEDURE uspGetAddress @City nvarchar(30) 

AS
SELECT *
FROM AdventureWorks.Person.Address
WHERE City LIKE @City + '%'
GO


Default Parameter Values

CREATE PROCEDURE uspGetAddress @City nvarchar(30) = NULL

AS
SELECT *
FROM AdventureWorks.Person.Address
WHERE City = @City
GO

Asked In: Many Interviews | Alert Moderator 
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Sriramnandha

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 5:54:21 PM