日期:2014-05-18  浏览次数:20393 次

如在createID表中的ID字段,原来为10000起, 现在想改为2600000起 ,用语句怎么写
在SQL Server2005中,如在createID表中的ID字段,原来为10000起, 现在想改为2600000起 ,用语句怎么写

------解决方案--------------------
SQL code

if OBJECT_ID('tb_test','u') is not null drop table tb_test
go
create table tb_test 
(
    id int identity(10000,1),
    name varchar(50)
)
go
insert into tb_test(name)
select 'ab' union all
select 'cd' union all
select 'ef'
go
select * from tb_test
/*
id          name
----------- --------------------------------------------------
10000       ab
10001       cd
10002       ef

(3 row(s) affected)
*/
go
--通过 DBCC CheckIdent(TB_Name,RESEED,StartNum) 方法改变
dbcc CHECKIDENT(tb_test,reseed,2600000)
go
insert into tb_test(name)
select 'gh' union all
select 'ii' union all
select 'gg'
go
select * from tb_test
go
/*
id          name
----------- --------------------------------------------------
10000       ab
10001       cd
10002       ef
2600001     gh
2600002     ii
2600003     gg
(6 row(s) affected)
*/

------解决方案--------------------
探讨

SQL code

if OBJECT_ID('tb_test','u') is not null drop table tb_test
go
create table tb_test
(
id int identity(10000,1),
name varchar(50)
)
go
insert into tb_test(name)
select 'ab' union al……

------解决方案--------------------
搂主ID字段是否自增字段,是不是需要以下语句?


SQL code
DBCC CHECKIDENT ("DBNAME.TABLENAME", RESEED, 2600000);

------解决方案--------------------
探讨
SQL code


if OBJECT_ID('tb_test','u') is not null drop table tb_test
go
create table tb_test
(
id int identity(10000,1),
name varchar(50)
)
go
insert into tb_test(name)
select 'a……

------解决方案--------------------
探讨

SQL code

if OBJECT_ID('tb_test','u') is not null drop table tb_test
go
create table tb_test
(
id int identity(10000,1),
name varchar(50)
)
go
insert into tb_test(name)
select 'ab' union al……