现在的位置: 首页 > 综合 > 正文

一条SQL语句 插入多条数据

2013年08月05日 ⁄ 综合 ⁄ 共 306字 ⁄ 字号 评论关闭

从表2中取一些数据插入表1中 方法如下

insert into table1 (colum1,colum2) select 'admin', colum2 from table2

在表2中 colum1 字段存在 可以用'admin' 替代 则插入的记录中 colum1 字段值全为 'admin'

查找前3条记录的SQL语句

select top 3 * from table1

一次插多条还有一种写法(对新表好用)

select colum1,colum2 into table1 from table2

如果表 1 中要插入的字段在表 2 中全存在 则写法如下

insert into table1(colum1,colum2) select colum1,colum2 from table2

抱歉!评论已关闭.