有选择性的生成一个表的插入脚本,不是选择全部数据生成
select 'insert into RoleRight(ID,RoleID,RightID,CreateDate,CreateID)
values('
+ CAST(ID AS NVARCHAR(50)) +','
+ CAST(RoleID AS NVARCHAR(50)) +','
+ CAST(RightID AS NVARCHAR(50)) +','''
+ CONVERT(varchar(20), CreateDate, 20) +''','
+ CAST(CreateID AS NVARCHAR(50))
+ ')' from RoleRight
WHERE Id>=1702
ORDER BY id DESC
生成的脚本如下,设置IDENTITY_INSERT是因为RoleRight的ID是自增长类型:
set IDENTITY_INSERT RoleRight ON
Go
insert into RoleRight(ID,RoleID,RightID,CreateDate,CreateID)
values(1702,5,52,'2014-04-28 17:50:49',0)
insert into RoleRight(ID,RoleID,RightID,CreateDate,CreateID)
values(1703,5,244,'2014-04-28 17:50:49',0)
insert into RoleRight(ID,RoleID,RightID,CreateDate,CreateID)
values(1704,5,246,'2014-04-28 17:50:49',0)
SET IDENTITY_INSERT RoleRight OFF
GO