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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - kwklover

给同为.NET开发者普及一点Oracle数据库经验 使用mencoder转换flv为ipad/iphone下能播放的mp4格式 - kwklover Lucene.net常见功能实现知识汇总 Lucene 1.9 多目录搜索的的一个bug 众里寻他千百度,蓦然回首,那人却在灯火阑珊处 小技巧:处理ASP提交的参数是经过GB2312 URL编码的 Lucene.net实现自定义排序笔记 模版引擎AderTemplate源代码分析笔记 T-SQL复习总结--用T-SQL创建,修改,管理,删除数据库 面向搜索的中文分词设计 需要整理研究的搜索引擎技术点(目录,无实际价值) 试用了一下Sqlite,总结和整理一下参考资料 数据结构与算法学习记录:快速排序 小总结:DotLucene如何才能快速生成索引? 小总结:如何表达用户是否禁止的概念 ? Web Spider提取编码方法总结 WebSpider的编码问题(乱码)浅析 VS2005 Winform程序不能启动调试,别忘了启动Terminal Services服务[记录] 系统问题解决记录:IIS 500内部错误之解决办法
问题总结:判断MS SQLSERVER临时表是否存在
kwklover · 2007-11-23 · via 博客园 - kwklover

 drop table  #tempcitys
 select * into #tempcitys from hy_citys

上面的语句第一次运行的时候就肯定出错了,但第二次就不会。
因为select * into #tempcitys from hy_citys自动创建了临时表#tempcitys ,第一次临时表不存在,drop table自然就出错了。
刚开始没反应过来,select * into是会自动创建临时表的。

所以比较可靠的做法,还是先判断临时表是否存在,然后再drop table
if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempcitys') and type='U')
   drop table #tempcitys

注意tempdb后面是两个. 不是一个的

考虑另外一种SQL的写法
insert into #tempcitys(cityid) select cityid from hy_citys
这种写法,#tempcitys则不会被自动创建,要使用#tempcitys,则需要先create table #tempcitys(cityid int)

原来我是搞混了。学艺不精的结果。:(