不用循环,如何用一条命令把一个表中的每条记录重复3次写入新表
时间:2011-11-26
来源:互联网
原表
a b
a b
c d
e f
g h
新表
a b
a b
a b
a b
c d
c d
c d
e f
e f
e f
g h
g h
g h
a b
a b
c d
e f
g h
新表
a b
a b
a b
a b
c d
c d
c d
e f
e f
e f
g h
g h
g h
作者: a000026 发布时间: 2011-11-26
SQL code
create table t1(id int,col varchar(10)) insert into t1 select 1,'aaa' insert into t1 select 2,'bbb' insert into t1 select 3,'ddd' insert into t1 select 4,'hhh' go insert into t1 select * from t1 go 2 select * from t1 /* id col ----------- ---------- 1 aaa 2 bbb 3 ddd 4 hhh 1 aaa 2 bbb 3 ddd 4 hhh 1 aaa 2 bbb 3 ddd 4 hhh 1 aaa 2 bbb 3 ddd 4 hhh (16 行受影响) */ drop table t1
作者: qianjin036a 发布时间: 2011-11-26
写入新表:
SQL code
SQL code
create table t1(id int,col varchar(10)) insert into t1 select 1,'aaa' insert into t1 select 2,'bbb' insert into t1 select 3,'ddd' insert into t1 select 4,'hhh' create table t2(id int,col varchar(10)) go insert into t2 select * from t1 go 3 select * from t2 /* id col ----------- ---------- 1 aaa 2 bbb 3 ddd 4 hhh 1 aaa 2 bbb 3 ddd 4 hhh 1 aaa 2 bbb 3 ddd 4 hhh (12 行受影响) */ drop table t1
作者: qianjin036a 发布时间: 2011-11-26
如果不允许用go n
则:
SQL code
则:
SQL code
create table t1(id int,col varchar(10)) insert into t1 select 1,'aaa' insert into t1 select 2,'bbb' insert into t1 select 3,'ddd' insert into t1 select 4,'hhh' create table t2(id int,col varchar(10)) go insert into t2 select * from t1 union all select * from t1 union all select * from t1 go select * from t2 /* id col ----------- ---------- 1 aaa 2 bbb 3 ddd 4 hhh 1 aaa 2 bbb 3 ddd 4 hhh 1 aaa 2 bbb 3 ddd 4 hhh (12 行受影响) */ drop table t1,t2
作者: qianjin036a 发布时间: 2011-11-26
SQL code
这样用 --> --> (Roy)生成測試數據 if not object_id('Tempdb..#T') is null drop table #T Go Create table #T([Col1] nvarchar(1),[Col2] nvarchar(1)) Insert #T select N'a',N'b' union all select N'a',N'b' union all select N'c',N'd' union all select N'e',N'f' union all select N'g',N'h' Go Select a.* from #T as a, (select top 3 ID from sysobjects) as b /* Col1 Col2 a b a b c d e f g h a b a b c d e f g h a b a b c d e f g h */
作者: roy_88 发布时间: 2011-11-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28