如何在SQL Server上创建存储过程 [英] how to create stored procedure on sql serever

查看:66
本文介绍了如何在SQL Server上创建存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那10行上有表格,所以我需要在一行上写一些逻辑

i have table on that 10 rows so i need to write some logic one row

推荐答案

如果您使用的是SQL Server 2008

使用SQl服务器mgmt控制台并登录

然后打开您的数据库>可编程性>存储过程



这是用于插入表格式的示例Sps


If you are using SQL server 2008

Use SQl server mgmt console and login

then open your database> Programability>Stored Procedure



This is a Sample Sps For Insertion Into Table Format


USE DBNAME
GO
/****** Object:  StoredProcedure [dbo].[USP_TMSAddFormat]    Script Date: 04/18/2012 18:35:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Tony Tom
-- Create date: 2-Sep-2011
-- =============================================
Create PROCEDURE [dbo].[USP_TMSAddFormat]---Sps Name 
	@FormatType	varchar(10),
	@CreatedBy	varchar(50),
	@ErrorDescription varchar(1000) OUTPUT 
	
AS
BEGIN
SET NOCOUNT ON 
BEGIN TRY
    BEGIN TRANSACTION;
	INSERT INTO  [Format]
           ([FormatType]
           ,[CreatedBy]
           ,[CreatedDate])
          
     VALUES
           (
            @FormatType,
            @CreatedBy,
            CURRENT_TIMESTAMP
           )
           
           
COMMIT TRANSACTION;
	return 0
END TRY			
	 
	 
BEGIN CATCH
    Set @ErrorDescription  = error_message()
    ROLLBACK TRAN

  End Catch;
End


这篇关于如何在SQL Server上创建存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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