什么是存储过程? [英] what is stored procedure?

查看:72
本文介绍了什么是存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是asp.net中的新手。请告诉我aspnet中的存储过程是什么。以及我们在asp.net中使用的原因。通过示例?以及如何调用它

解决方案

存储过程是一组带有指定名称的SQL语句,它以编译形式存储在数据库中,以便它可以由许多程序共享。存储过程的使用有助于控制对数据的访问(最终用户可以输入或更改数据但不编写过程),保持数据完整性(以一致的方式输入信息),并提高生产率(存储中的语句)程序只需要写一次)。

存储过程的优点



a)存储过程允许模块化编程。你可以创建程序一次,将其存储在数据库中,并在程序中多次调用它。



b)存储过程允许更快的执行。如果操作需要重复执行大量SQL代码,则存储过程可以更快。它们在首次执行时被解析和优化,并且存储过程的编译版本保留在内存高速缓存中供以后使用。这意味着存储过程不需要在每次使用时重新分析和重新优化,从而导致执行时间快得多。



c)存储过程可以减少网络流量。需要数百行Transact-SQL代码的操作可以通过执行过程中代码的单个语句来执行,而不是通过网络发送数百行代码。



d)存储过程为您的数据提供更好的安全性。即使用户没有直接执行过程语句的权限,也可以授予用户执行存储过程的权限。



在SQL中我们有不同类型的存储过程有没有



a)系统存储过程

b)用户定义的存储过程

c)扩展存储过程


在asp.net中调用存储过程



 SqlConnection con =  new  SqlConnection( 您的连接字符串); 
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
cmd.CommandText = StoredProcedureName;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
con.Open();
dr = cmd.ExecuteReader();
whiledr.Read()
{
// 可通过DataReader访问数据这里的对象。
}
con.Close();




请查看以下链接





http://www.aspdotnet-suresh.com/2011/07/what-is-stored-procedure-in-sql-server.html [ ^ ]


您好,



一些有用的链接供您从本网站本身参考



SQL Server存储过程概述 [ ^ ]



如何在ASP.net中使用C#与Sql Server 2005一起使用存储过程 [ ^ ]



如何在asp.net c#代码中调用存储过程 [ ^ ]



使用ASP.NET中的存储过程插入数据 [ ^ ]



谢谢


guys i m new in asp.net..pls tell me what is stored procedure in aspnet. and why we use in asp.net. by example?and how to call it

解决方案

A Stored Procedure is a set of SQL statements with an assigned name that's stored in the database in compiled form so that it can be shared by a number of programs. The use of stored procedures can be helpful in controlling access to data (end-users may enter or change data but do not write procedures), preserving data integrity (information is entered in a consistent manner), and improving productivity (statements in a stored procedure only need to be written one time).
Advantage of stored procedure

a) Stored procedure allows modular programming.You can create the procedure once, store it in the database, and call it any number of times in your program.

b) Stored Procedure allows faster execution. If the operation requires a large amount of SQL code is performed repetitively, stored procedures can be faster. They are parsed and optimized when they are first executed, and a compiled version of the stored procedure remains in memory cache for later use. This means the stored procedure does not need to be reparsed and reoptimized with each use resulting in much faster execution times.

c) Stored Procedure can reduce network traffic.An operation requiring hundreds of lines of Transact-SQL code can be performed through a single statement that executes the code in a procedure, rather than by sending hundreds of lines of code over the network.

d) Stored procedures provide better security to your data. Users can be granted permission to execute a stored procedure even if they do not have permission to execute the procedure's statements directly.

In SQL we are having different types of stored procedures are there

a) System Stored Procedures
b) User Defined Stored procedures
c) Extended Stored Procedures

Calling stored procedure in asp.net

SqlConnection con = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
con.Open();
dr= cmd.ExecuteReader();
whiledr.Read()
{
// Data is accessible through the DataReader object here.
}
con.Close();


Hi ,
Please check below link


http://www.aspdotnet-suresh.com/2011/07/what-is-stored-procedure-in-sql-server.html[^]


Hi,

Some useful links for your reference from this site itself

Overview of SQL Server Stored Procedure[^]

How to use Stored Procedure in ASP.net using C# with Sql Server 2005[^]

how to call stored procedure in asp.net c# code[^]

Insert Data Using Stored Procedure in ASP.NET[^]

Thanks


这篇关于什么是存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆