zoukankan      html  css  js  c++  java
  • 产生sql表中表示字段, 实现自增列

    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_NULLS ON
    GO

    ALTER  Procedure GetMaxID
     /* Param List */
     @Table varchar(20),
     @col varchar(20),
     @MaxID bigint output
    AS

    /******************************************************************************
    **  File:
    **  Name: GetMaxID
    **  Desc: 获得指定表的指定列的累加最大ID值
    **
    **  This template can be customized:
    **             
    **  Return values:
    **
    **  Called by:  
    **             
    **  Parameters:
    **  Input @Table 表名      Output @MaxID 最大ID
    **            @col 列名
    **            ----------       -----------
    **
    **  Date: 06-7-13
    *******************************************************************************
    **  Change History
    *******************************************************************************
    **  Date:  Author:        Description:
    **  --------  --------    -------------------------------------------
    **   
    *******************************************************************************/
    set nocount on

     Declare @SelectString varchar(200)
     Set @SelectString='Insert into #temptable select  max('+@col+')  from  '  + @Table + ' WITH (TABLOCKX, HOLDLOCK) '
     Create Table #temptable (TempID bigint)
     Exec (@SelectString)
     Select @MaxID=TempID from #temptable
     If @MaxID Is Null Set @MaxID=0
     Set @MaxID=@MaxID+1
     Drop Table #temptable
     
    set nocount on

    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO

  • 相关阅读:
    SNMP监控一些常用OID表的总结
    微信公众号开发(三)----服务号客服消息
    微信公众号开发(二)---验证服务与回复消息
    微信公众号开发(一)-----准备工作
    leveldb文章列表
    TinyIM流程之删除好友
    TinyIM流程之添加好友
    《软件创富----共享软件创业之道》读后感
    TinyIM流程之用户注销
    TinyIM流程之用户退出登录
  • 原文地址:https://www.cnblogs.com/VirtualMJ/p/515428.html
Copyright © 2011-2022 走看看