192Microsoft Visual Studio 2010: A Beginner’s Guide
copy of the diagram,
In addition to tables and diagrams, you can add database views, stored procedures, functions, synonyms, types, and assemblies. Most of these database items are for advanced scenarios, but it’s important that you know about stored procedures, which are covered next.
Adding Stored Procedures
A stored procedure is code that is written in SQL and saved as part of a database. It is a method stored in the database itself, and not in your program code; hence the term stored procedure. In this section, I’ll show you how to create and execute a stored procedure. Later sections of this chapter will show you how to execute this stored procedure, which runs a data query, through LINQ to SQL.
To create a stored procedure,
Listing 7-1 Stored procedure example
CREATE PROCEDURE GetCustomers
AS
declare @cust_count int
select @cust_count = count(*) from Customer if @cust_count > 0
begin
select [Name] from Customer
end return
Listing