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'