把某个表的自增长的字段改为非自增长,且主键不变

--将酒水组表的主键改为非自增的

alter table RecipeGroups add useridtmp int null

go

update RecipeGroups set useridtmp = RecipeGroup_ID

go

declare @a varchar(100)

select @a=name from sysobjects where parent_obj=(select id from sysobjects where name='RecipeGroups') and xtype='PK'

if @a is not null

  exec('alter table RecipeGroups drop '+@a)

alter table RecipeGroups drop column RecipeGroup_ID

go

alter table RecipeGroups add RecipeGroup_ID int null

go

update RecipeGroups set RecipeGroup_ID = useridtmp

go

alter table RecipeGroups drop column useridtmp

go

alter table RecipeGroups alter column RecipeGroup_ID int not null

go

alter table RecipeGroups add primary key (RecipeGroup_ID)

go