[usertable]
id username pwd
1 xxx qq
2 yyy qq
3 zzz qqid 是标识自动增长列insert into usertable select top 1 * from usertable SET IDENTITY_INSERT products ON出错:
"仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'usertable' 中为标识"我想做。。:我想实现复制的功能,但由于表中有很多字段,如果每个都列出。感觉有点麻烦,所以想把整行自身复制一次,结果就是:表中存在 除id值不同之外,两条相同的记录。高手们,有没有办法呢?
id username pwd
1 xxx qq
2 yyy qq
3 zzz qqid 是标识自动增长列insert into usertable select top 1 * from usertable SET IDENTITY_INSERT products ON出错:
"仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'usertable' 中为标识"我想做。。:我想实现复制的功能,但由于表中有很多字段,如果每个都列出。感觉有点麻烦,所以想把整行自身复制一次,结果就是:表中存在 除id值不同之外,两条相同的记录。高手们,有没有办法呢?
insert into usertable select top 1 * from usertable
SET IDENTITY_INSERT products OFF这样式式
--创建测试表
create table usertable(id int identity(1,1),username varchar(10),pwd varchar(10))
insert into usertable select 'xxx','qq'
union all select 'yyy','qq'
union all select 'zzz','qq'
--插入
declare @sql varchar(8000)
set @sql=''
select @sql=@sql+','+[name] from syscolumns where id=object_id('usertable') and [name]<>'id' order by colid
set @sql=stuff(@sql,1,1,'')
exec('insert into usertable('+@sql+') select top 1 '+@sql+' from usertable')
--查询
select * from usertable
--删除测试表
drop table usertable
"仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'usertable' 中为标识"
感谢你的帮助
其实我想不涉及细节字段名,因为字段很多啊,逐个打出来,非常花时间。。我就只是想复制一行之后,插入一行,除了ID 变之外,其它值仍然保留..也就是那个 ID 不能插值的问题了