如何在有自增字段的两个表中移动数据?(50分)

  • 主题发起人 主题发起人 xyt3dnow
  • 开始时间 开始时间
X

xyt3dnow

Unregistered / Unconfirmed
GUEST, unregistred user!
两个结构一样的表(sql7.0),使用adoquery联接,有一个自增加变量从1开始递增。
如何将b表的数据移动到a表,不是复制哦。
我用了insert into a select * from b,提示出错。
在sql出错:an explicit value for idintity column in table 'b' can only
be specified when a column list is used and identity_insert is on
 
一条条追加,注意自增字段空着不要写,数据库会自动加的,没有冲突
 
insert into a (field1,field2) select field1,field2 from b
排除自增字段试试
 
能给出程序吗?我的a表完全是空的阿,没有动过自增字段阿。
 
insert into a (c,d,e,...)select c,d,e,... from b
c,d,e为两个表中的字段名,不要包括自增字段
 
那自增字段是不是设置和b表的起始值一样?
 
我想要的效果是数据的移动而不是拷贝
 
你的意思是插入到a表后,b表的数据就没有了,如果这样,你要插入完成后再删除b表
insert into a (c,d,e,...)select c,d,e,... from b
delete select c,d,e,... from b
自增字段是数据库自己改变的,你不用管它

 
不一定是全部删除阿,如果有时候只是移动一些符合条件的记录。
 
一样的
insert into a (c,d,e,...)select c,d,e,... from b where c>222
delete select c,d,e,... from b where c>222
 
yanghai0437、各位大侠,谢谢了,其实我程序的构思是一个类似归档的操作,就是
在一个 DBGrid中选中一条记录,然后将其移动到另外的一个结构相似的表b中,
后面的条件怎么写?就是where后面的语句,怎么和箭头指向的 DBGrid2中的记录联系起来。
 
值 = query.fieldbyname(自增字段).value
insert into a (c,d,e,...)select c,d,e,... from b where 自增字段=值
delete select c,d,e,... from b where 自增字段=值
这个值我想你应该可以得到.
上面是插入到a表,插入后这条记录的自增字段的值不一定和原来的相同。
 
多人接受答案了。
 
后退
顶部