</pre>在sql server 中用一条insert into 插入多条记录的方法:<p></p><p>1、insert into [tablename] |(列名称) values (),(),...</p><p>2、insert into [tablename] |(列名称) select .... union all</p><p><span style="white-space:pre"></span>select ... union all</p><p><span style="white-space:pre"></span> <span style="white-space:pre"> </span>select ...</p><p><span style="font-family:monospace"><span style="white-space:pre; background-color:rgb(240,240,240)">范例如下:</span></span></p><p><span style="font-family:monospace"><span style="white-space:pre; background-color:rgb(240,240,240)"></span></span></p><pre name="code" class="sql">if exists(select 1 from sysobjects where id = OBJECT_ID(N'tMoney')
and OBJECTPROPERTY(id,N'IsUserTable')=1
)
drop table tMoney
create table tMoney(
nId int identity(1,1) primary key,
sName varchar(20),
nMyMoney int
)
insert into tMoney(sName,nMyMoney)
select '刘备',100 union all
select '关羽',200
insert into tMoney(sName,nMyMoney) values
('刘备',100),
('关羽',200)
select * from tMoney
SQL Server 一条 insert 插入多条记录
最新推荐文章于 2024-03-29 15:34:12 发布