[英]How to write stored procedure?
I am learning how to write a stored procedure. 我正在学习如何编写存储过程。 I kinda get it but I don't.
我有点得到它,但我没有。 I know it goes something like this..
我知道它是这样的......
CREATE PROCEDURE|PROC <sproc name>
[<parameter name> [schema.]<data type> [VARYING] [=<default value>] [OUT[PUT]]
[READONLY]
[,<parameter name> [schema.]<data type> [VARYING] [=<deafult value>] [OUT[PUT]]
[READONLY]
[,...
...
]]
[WITH
RECOMPILE|ENCRYPTION|[EXECUTE AS{ CALLER|SELF|OWNER|<'user name'>}]
[FOR REPLICATION]
AS
<code> | EXTERNAL NAME <assembly name>.<assembly class>.<method>
So what I am stuck on and I am trying to understand is this.. Write a stored procedure that accepts a Territory ID, Territory Description, and Region ID and inserts them as new row in the Territories table in Northwind. 所以我坚持并且我想要理解的是..编写一个接受区域ID,区域描述和区域ID的存储过程,并将它们作为新行插入Northwind的Territories表中。
Ok so I know I could do something like this I believe: 好的,所以我知道我可以做这样的事情我相信:
USE Northwind
GO
CREATE PRO spTerritory
AS
SELECT Territory ID,Territory Description,RegionID
From dbo.Territories
But then I can be wrong. 但后来我错了。 But I dont know where to insert then as a new row in the table.
但我不知道在哪里插入作为表中的新行。 I know I would use something like @newrow or @rows along that line.
我知道我会在这条线上使用类似@new或@rows的东西。 If someone can help me understand who to do a sproc I would be greatful.
如果有人可以帮助我了解谁做了一个sproc我会很高兴。
Microsoft如何: 创建存储过程(SQL Server Management Studio)
USE [SchoolData] GO 使用[学校数据] GO
For getting the all data 获取所有数据
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO create procedure [dbo].[GetDepartment] as select Id,Name,Description,IsDeleted from Departments where IsDeleted=0 SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO创建过程[dbo]。[GetDepartment]作为选择Id,名称,描述,IsDeleted来自部门IsDeleted = 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.