码迷,mamicode.com
首页 > 数据库 > 详细

sql修改自增长ID

时间:2016-03-21 17:53:23      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:

ALTER PROCEDURE [sp_Table_SetIdentity] 
     @Table varchar(100) 
    ,@Schema    varchar(100) 
AS
BEGIN
    DECLARE @vSQL nvarchar(max) 
     
    -- drop PK on [SchoolID] 
    SET @vSQL = N‘ 
ALTER TABLE  #Schema#.#Table# 
    DROP CONSTRAINT PK_#Table#; 
‘
    SET @vSQL = Replace(@vSQL, ‘#Table#‘, @Table) 
    SET @vSQL = Replace(@vSQL, ‘#Schema#‘, @Schema) 
print @vSql 
    EXEC (@vSql) 
     
    -- rebuild IDENTITY column 
    SET @vSQL = N‘ 
ALTER TABLE  #Schema#.#Table# 
    DROP COLUMN [SchoolID]; 
     
ALTER TABLE  #Schema#.#Table# 
    ADD [SchoolID] int IDENTITY(1, 1) NOT NULL; 
     
ALTER TABLE [#Schema#].[#Table#] ADD  CONSTRAINT [PK_#Table#] PRIMARY KEY CLUSTERED  
( 
    [SchoolID] ASC 
)WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = ON, ONLINE = OFF) ON [PRIMARY]; 
‘
    SET @vSQL = Replace(@vSQL, ‘#Table#‘, @Table) 
    SET @vSQL = Replace(@vSQL, ‘#Schema#‘, @Schema) 
print @vSql 
    EXEC (@vSql) 
END

exec [sp_Table_SetIdentity] ‘Area_School‘,‘dbo‘

 

sql修改自增长ID

标签:

原文地址:http://www.cnblogs.com/studyjava/p/5302625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!