什么是“存储过程”,它们是如何工作的?
存储过程是由什么组成的(每个东西都必须是存储过程)?
什么是“存储过程”,它们是如何工作的?
存储过程是由什么组成的(每个东西都必须是存储过程)?
当前回答
在存储过程中,语句只被写入一次,从而减少了客户端和服务器之间的网络流量。 我们也可以避免Sql注入攻击。
Incase if you are using a third party program in your application for processing payments, here database should only expose the information it needed and activity that this third party has been authorized, by this we can achieve data confidentiality by setting permissions using Stored Procedures. The updation of table should only done to the table it is targeting but it shouldn't update any other table, by which we can achieve data integrity using transaction processing and error handling. If you want to return one or more items with a data type then it is better to use an output parameter. In Stored Procedures, we use an output parameter for anything that needs to be returned. If you want to return only one item with only an integer data type then better use a return value. Actually the return value is only to inform success or failure of the Stored Procedure.
其他回答
存储过程将帮助您在服务器中编写代码。您可以传递参数并查找输出。
create procedure_name (para1 int,para2 decimal)
as
select * from TableName
存储过程主要用于在数据库上执行某些任务。例如
从数据上的一些业务逻辑获取数据库结果集。 在一次调用中执行多个数据库操作。 用于将数据从一个表迁移到另一个表。 可用于其他编程语言,如Java。
对于简单的,
存储过程是存储程序,存储在数据库中的程序或函数。
每个存储的程序都包含一个由SQL语句组成的主体。该语句可以是由几个用分号(;)分隔的语句组成的复合语句。
CREATE PROCEDURE dorepeat(p1 INT)
BEGIN
SET @x = 0;
REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
END;
存储过程是一组预编译的SQL语句,用于执行特殊任务。
示例:如果我有一个Employee表
Employee ID Name Age Mobile
---------------------------------------
001 Sidheswar 25 9938885469
002 Pritish 32 9178542436
首先,我正在检索Employee表:
Create Procedure Employee details
As
Begin
Select * from Employee
End
在SQL Server上运行此过程:
Execute Employee details
--- (Employee details is a user defined name, give a name as you want)
然后,我将值插入到Employee表中
Create Procedure employee_insert
(@EmployeeID int, @Name Varchar(30), @Age int, @Mobile int)
As
Begin
Insert Into Employee
Values (@EmployeeID, @Name, @Age, @Mobile)
End
在SQL Server上运行参数化过程:
Execute employee_insert 003,’xyz’,27,1234567890
--(Parameter size must be same as declared column size)
示例:@Name Varchar(30)
在Employee表中,Name列的大小必须是varchar(30)。
存储过程是一个预编译的SQL语句集,它执行一些特定的任务。 存储过程应该使用EXEC单独执行 存储过程可以返回多个参数 存储过程可用于实现事务