首页 > 技术文章 > sql表与表之间的数据操作

oneall 2019-04-26 10:56 原文

--把一张表的内容更新到另一张表
update 表1
set 表1.Store=t2.Name
from 表2 t2 where 表1.id=t2.id


--备份一张表
create table tab_new like tab_old (使用旧表创建新表)
create table tab_new as select col1,col2… from tab_old definition only
--(试了以上两句无效)
select * into newtable from oldtable; 如果不想导记录,只想生成表结构 :select * into newtable from oldtable where 1=2;
如果newtable已存在,想导入记录:insert into newtable select * from oldtable where ...


--sqlserver复制表数据到另一个表
SQL Server中如果目标表存在:
insert into 目标表 select * from 原表;
SQL Server中,如果目标表不存在:
select * into 目标表 from 原表;

 

推荐阅读