日期:2014-05-19  浏览次数:20537 次

问一个简单的sql语句
往一个表table里插100条数据,其他的字段都是从另一个表table2中取出对应插入,但是表table中有个字段   id,是作为主键的,我想是他的值是800到900,该如何写啊?

------解决方案--------------------
select table2.字段,id=identity(int,800,1) into #t from table2

insert into table
select * from #t
------解决方案--------------------
借用下臨時表

Select ID = Identity(Int, 800, 1), * Into #T From table2
Insert [table] Select * From #T
Drop table #T
------解决方案--------------------
select top 100 *,IDENTITY (int,800,1) as id
into # from table2

insert table1(...,id)
select ...,id from #

drop table #


------解决方案--------------------
select table2.字段,id=identity(int,800,1) into #t from table2

select top 101 id=identity(int,800,1) into #t1 from syscolumns,sysobjects

insert into 表table
select #t.* from #t1
left join #t on #t1.id=#t.id
------解决方案--------------------
select top 100 identity(int,800,1) as id,* into #aa from table2

insert into table1 select * from #aa