081225区别是一个是内存中表declare,一个是实现存在的表。
- --创建虚表的方法
- if object_id('tempdb..#')is not null drop table #
- go
- create table #(num varchar(10))
- insert # select 123
- insert # select 456
- insert # select 'ad'
- insert # select '2008-12-25'
- select cast(num as datetime) from # where isdate(num)=1
- --select cast(num as int) from # where isnumeric(num)=1
- --cast(str as int)转化 isnumeric(num)判断能不能转化为数字
- --cast(str as nvarchar)
081218第一个临时表应用
- --================临时表入门示例==================
- --================张树强==081218================
- create procedure [dbo].[Test_TempTable]
- as
- begin
- declare @indextable table(id int identity(1,1),nid int) --这个临时表,有一个id主键,自增。
- insert into @indextable (nid) select id from ttest --把数据插入临时表
- select * from @indextable
- end
- GO
临时表与永久表相似,但临时表存储在 tempdb 中,当不再使用时会自动删除。
临时表有局部和全局两种类型
2者比较:
局部临时表的名称以符号 (#) 打头
仅对当前的用户连接是可见的
当用户实例断开连接时被自动删除
全局临时表的名称以符号 (##)
sysobjects这个表里存放临时表的信息。
if object_id('tempdb..#temptable1')is not null
begin
drop table #temptable1
end
不太理解这些语句,这里判断一下,然后删除临时表。代码运行通过。
http://www.cnblogs.com/mjgforever/archive/2008/08/15/849201.html
http://blog.chinaunix.net/u/15773/showart_348981.html
create table temptable1(gid varchar(50))
insert into temptable1
select gid from t_Goods
select * from temptable1