您的当前位置:首页 --> MSSQL教程 |
Sql Server临时表和游标的使用小结 |
浏览次数:1192 关键词 ( ) |
1.临时表 临时表与永久表相似,但临时表存储在 tempdb 中,当不再使用时会自动删除。 2者比较: 局部临时表的名称以符号 (#) 打头 在2个查询分析器我们都允许下面的语句: use pubs go select * into #tem from jobs 分别为2个用户创建了2个局部临时表 SELECT * FROM [tempdb].[dbo].[sysobjects] where xtype='u' 判断临时表的存在性: if object_id('tempdb..#tem') is not null begin print 'exists' end else begin print 'not exists' end 特别提示: exec('select * into #tems from jobs') select * from #tems 2。在存储过程中用到的临时表在过程运行完毕后会自动删除 ii。游标 判断存在性: if CURSOR_STATUS('global','游标名称') =-3 and CURSOR_STATUS('local','游标名称') =-3 begin print 'not exists' end SELECT * FROM [tempdb].[dbo].[sysobjects] where xtype='u' 判断临时表的存在性: if object_id('tempdb..#tem') is not null begin print 'exists' end else begin print 'not exists' end 特别提示: exec('select * into #tems from jobs') select * from #tems 2。在存储过程中用到的临时表在过程运行完毕后会自动删除 ii。游标 判断存在性: if CURSOR_STATUS('global','游标名称') =-3 and CURSOR_STATUS('local','游标名称') =-3 begin print 'not exists' end SELECT * FROM [tempdb].[dbo].[sysobjects] where xtype='u' 判断临时表的存在性: if object_id('tempdb..#tem') is not null begin print 'exists' end else begin print 'not exists' end 特别提示: exec('select * into #tems from jobs') select * from #tems 2。在存储过程中用到的临时表在过程运行完毕后会自动删除 ii。游标 判断存在性: if CURSOR_STATUS('global','游标名称') =-3 and CURSOR_STATUS('local','游标名称') =-3 begin print 'not exists' end |
下一条 Sqlserver事务备份和还原的实例代码(必看) 上一条 暂无 |
数千企业与站长的选择,7*24小时稳定运行
了解更多套餐详细