原主表结构: ID TITLE CONTENT 原从表结构: ID 主表ID CONTENT(主表的ID和从表的主表ID关联)现主表结构: A B C 现从表结构: D E F (主表的A和从表的E关联)现在想把原来两个表的部分数据导入到新表中,用SQL语句该咋办呢?
试试: alter table 现主表 add Id int insert into 现主表(Id, B, C) select Id,Title, Content from 原主表 insert into 现从表(E, F) select a.A, b.ConTent from 现主表 a join 原从表 b on a.Id = b.主表Id alter table 现主表 drop column Id
alter table 现主表 add Id int go insert into 现主表(Id, B, C) select Id,Title, Content from 原主表 insert into 现从表(E, F) select a.A, b.ConTent from 现主表 a join 原从表 b on a.Id = b.主表Id go alter table 现主表 drop column Id
select a.A, b.ConTent from 现主表 a join 原从表 b on a.Id = b.主表Id这句不对吧…………
insert into 现从表(E, F) select a.A, b.ConTent from 现主表 a join 原从表 b on a.Id = b.主表Id这句不对
ID TITLE CONTENT
原从表结构:
ID 主表ID CONTENT(主表的ID和从表的主表ID关联)现主表结构:
A B C
现从表结构:
D E F
(主表的A和从表的E关联)现在想把原来两个表的部分数据导入到新表中,用SQL语句该咋办呢?
alter table 现主表 add Id int
insert into 现主表(Id, B, C) select Id,Title, Content from 原主表
insert into 现从表(E, F)
select a.A, b.ConTent from 现主表 a join 原从表 b on a.Id = b.主表Id
alter table 现主表 drop column Id
列名 'Id ' 无效。
服务器: 消息 207,级别 16,状态 1,行 2
列名 'Id ' 无效。
go
insert into 现主表(Id, B, C) select Id,Title, Content from 原主表
insert into 现从表(E, F)
select a.A, b.ConTent from 现主表 a join 原从表 b on a.Id = b.主表Id
go
alter table 现主表 drop column Id
----------------------------
怎么变??????说清楚,新主表的A怎么来的???
还有新从表D是也变了,还是沿用原从表的Id
----------------------------
怎么变??????说清楚,新主表的A怎么来的???
还有,新从表D是变了,还是延用原从表的Id????