设源表为testsource,目标表为testdestination;
将源表中的记录插入到目标表中
1. insert into ... select 语句:将源表中的记录插入到目标表中,假设目标表已经存在
1)若目标表和源表的结构一样
insert into testdestination select * from testsource
2)若不一样:就要指明要插入的字段名
insert into testdestination(id,name) select id,name from testsource
2.select...into...语句:将源表中的记录插入到目标表中,同时创建目标表,目标表的结构根据查询结果决定
select * into testdestination from testsource
select a.au_lname,c.title into authortitles from authors a, titleauthor b,titles c
where a.au_id=b.au_id and b.title_id=c.title_id
博客介绍了在SQL Server中,将源表testsource的记录插入目标表testdestination的方法。一是使用insert into... select语句,目标表已存在,结构相同可直接插入,不同则需指明字段名;二是用select...into...语句,插入记录同时创建目标表,结构由查询结果决定。
7577

被折叠的 条评论
为什么被折叠?



