sql修改自增长ID
Posted 以勤补拙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql修改自增长ID相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章