首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

更新SQL语句?该如何解决

2012-01-23 
更新SQL语句?createtabletest(idint)insertintotestselectnullinsertintotestselectnullinsertintotestsel

更新SQL语句?


create   table   test

(

id   int
)

insert   into   test   select   null

insert   into   test   select   null

insert   into   test   select   null


insert   into   test   select   230
insert   into   test   select   250
insert   into   test   select   433


select   *   from   test
/*
将id列更新为如下形式

id
1
2
3
4
5
6

更新之后把id列设置为identity(1,1)进行递增,不知道可不可以
*/
drop   table   test

[解决办法]
把此列删了再加一个自增列,干嘛改了再增
[解决办法]

create table test(id int)
insert into test select null
insert into test select null
insert into test select null
insert into test select 230
insert into test select 250
insert into test select 433
go

declare @i int
set @i=0

update test set @i=@i+1,id=@i

select * from test
go

drop table test
go
[解决办法]
--这种方式最简单

declare @i int

set @i=0

update 表名 set @i=@i+1,id=@i

[解决办法]
create table test

(

id int
)

insert into test select null

insert into test select null

insert into test select null


insert into test select 230
insert into test select 250
insert into test select 433


select * from test

select identity(int,1,1) as sid,id into #t from test
select id = sid from #t
drop table #t

drop table test
[解决办法]
更新之后把id列设置为identity(1,1)进行递增,不知道可不可以
---------------------
要是这样的话:

alter table test add bh int identity(1,1)

alter table test drop column id

exec sp_rename 'test.bh ', 'id ', 'column '

热点排行