惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
Google DeepMind News
Google DeepMind News
Security Archives - TechRepublic
Security Archives - TechRepublic
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
The Hacker News
The Hacker News
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
F
Full Disclosure
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Security @ Cisco Blogs
H
Hacker News: Front Page
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
B
Blog RSS Feed
H
Heimdal Security Blog
Google Online Security Blog
Google Online Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
V2EX - 技术
V2EX - 技术
V
Vulnerabilities – Threatpost
Help Net Security
Help Net Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
W
WeLiveSecurity
T
Tenable Blog
D
DataBreaches.Net
Martin Fowler
Martin Fowler
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
S
Secure Thoughts
O
OpenAI News
L
LINUX DO - 热门话题
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
Jina AI
Jina AI
J
Java Code Geeks
Know Your Adversary
Know Your Adversary
IT之家
IT之家
Latest news
Latest news
Cloudbric
Cloudbric

博客园 - 早班火车

很还念这里。。。说些什么呢。。。 程序,好亲切~ IE与DOM下访问内联样式和外部样式表的常用方法总结 关于javascript中的事件学习及总结 总结了几个常用的sql server系统表的使用 在做一个小网站的一些心得与遇到的问题总结,为以后方便查阅。 一步一步教你抓数据——用.net精确提取网站数据的通用方法 也来为自己的博客加个花,兼AJAX跨域的一点疑问。 关于IE缓存和AJAX的一点思考和疑问 退一步海阔天空:抛开思维定势 DOCTYPE:你可能不知道的 我的2007--从2008做起,加油! javascript常用验证 正则表达式参考手册__Mini版 树的操作(绑定数据库,添加新节点,删除节点)(转载加实现) 一段好用的ajax和div漂浮显示效果实现 ajax小贴士 好用的缓存类 javascript操纵剪贴板
用sql脚本一条条导数据的两种方法,需返回唯一标识@@IDENTITY作为插入到第二个表用。
早班火车 · 2008-03-12 · via 博客园 - 早班火车

因为实际需求需要用sql脚本导数据到另一个表中,且必须返回一个@@IDENTITY的唯一标识。
作为插入到另一个表的字段用。
比如说新闻,有newstitlenote表和newdetail表,分别存放的是基本信息和新闻详细内容
为了保持数据同步所以必须返回唯一标识一条条插入,而不能用insert into...select...
这里用了两种方法:
1游标

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
--唯一标识
declare @currentvalue int declare @isshow int=0
declare @cur_checkdate datetime
declare @cur_newsline varchar(200)
declare @cur_quarry varchar(50)
declare @cur_parentid int declare cur_custer cursor
for  
select [newsday],[newsline],[Quarry],[newstype] from [News_Fund_Content] where newstype=4 order by newsday desc
--打开游标
open cur_custer
--读取一行
fetch cur_custer into @cur_checkdate,@cur_newsline,@cur_quarry,@cur_parentid
while (@@fetch_status =0)
    
begin 
        
insert into  [news_title_note]([check_date],[newsline],[Quarry],[isshow],[parentid])
        
values ( @cur_checkdate,@cur_newsline,@cur_quarry,,@isshow,@cur_parentid)
        
select @currentvalue = @@IDENTITY
        
--唯一标识用作插入到news_classlist用
        print @currentvalue
        
INSERT INTO [dbo].[news_classlist]([noteid],[classname],[parentid])
        
values  ( @currentvalue,@classname,@newstype)
        
fetch cur_custer into @cur_checkdate,@cur_newsline,@cur_quarry,@cur_parentid
    
end
--关闭游标
close cur_custer
--撤销游标
deallocate cur_custer


2创建临时表查一条删一条

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GOcreate table #news
(
    newsday 
datetime,
    newsline 
varchar(100),
    quarry 
varchar(50),
    newstype 
int
)
--把所有数据导入到临时表中
insert into #news select [newsday],[newsline],[Quarry],[newstype] from [News_Fund_Content] where newstype=4
declare @newsday datetime
declare @quarry varchar(50)
declare @newsline varchar(100)
declare @newstype int 
declare @isshow int=0
declare @classname varchar(50)
set @classname = '后勤'
--返回唯一标识
declare @currentvalue intwhile (select count(1from #news where newstype=4> 0
    
begin
        
set @newsday = select top 1 @newsday = [newsday]@quarry = [quarry]@newsline=[newsline] , @newstype=[newstype] 
        
from #news order by newsday desc
        
insert into [news_title_note]([check_date],[newsline],[Quarry],[isshow],[parentid]
        
values ( @newsday,@newsline,@quarry,@isshow,@newstype)
        
--取唯一标识用作下个表的插入
        select @currentvalue = @@IDENTITY
        
print @currentvalue
        
INSERT INTO [dbo].[news_classlist]([noteid],[classname],[parentid])
        
values  ( @currentvalue,@classname,@newstype)
        
--在临时表中删除这条新闻
        delete #news where newsline = @newsline
    
end

3当然还可以用程序写~。
只不过觉得比较麻烦还得建个项目啥的。

遇到text字段无法导入的问题,在博问中请教了下,
有说设定@newscontent 时设定为varchar并且设定的范围大点可解决导入text字段的问题。
试试再说~先谢过~

网上说游标比较慢,具体自己没有测试过,所以先推荐第二种方法吧。
欢迎讨论指正~