SQL Server之SELECT INTO 和 INSERT INTO SELECT案例详解


当前第2页 返回上一页

MS SqlServer:Select column1,column2…… into Table2 From Table1 或 Select * into Table2 From Table1

例:

--Oracle
--1.创建表
create TABLE Table1
(
    a varchar(10),
    b varchar(10),
    c varchar(10)
) ;

commit;
--2.创建测试数据
Insert into Table1 values('赵','asds','90');
Insert into Table1 values('钱','asds','100');
Insert into Table1 values('孙','asds','80');
Insert into Table1 values('李','asds',null);
commit;
--3.复制table1数据到table2中
Create Table Table2 as select a,b,c From table1;
Commit;
--或(这两种方式的sql只能应用一次)
Create table table2 as select * From Table1;
Commit;
--删除表
drop table table1;
drop table table2;
commit;
--MS SqlServer
--1.创建表
create TABLE Table1
(
    a varchar(10),
    b varchar(10),
    c varchar(10)
) ;

commit;
--2.创建测试数据
Insert into Table1 values('赵','asds','90');
Insert into Table1 values('钱','asds','100');
Insert into Table1 values('孙','asds','80');
Insert into Table1 values('李','asds',null);
commit;
--3.复制table1数据到table2中
Select a,b,c into Table2 From table1;
Commit;
--或(这两种方式的sql只能应用一次)
Select * into table2 From Table1;
Commit;
--删除表
drop table table1;
drop table table2;
commit;

到此这篇关于SQL Server之SELECT INTO 和 INSERT INTO SELECT案例详解的文章就介绍到这了,更多相关SQL Server之SELECT INTO 和 INSERT INTO SELECT内容请搜索

更多SQL内容来自木庄网络博客


打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...