有趣的自定义类型:表
2013-08-27 12:34
253 查看
--创建自定义类型,这里的自定义类型是表,可存储记录 CREATE TYPE LocationTableType AS TABLE ( LocationName VARCHAR(50) , CostRate INT ) GO declare @t LocationTableType /* --通过表变量来中转 declare @tt table ( LocationName VARCHAR(50),CostRate INT ) insert into @tt select '123',1 insert into @t select * from @tt */ --可以直接把数据添加到LocationTableType类型中 --可以存储多条记录 insert into @t select '123',1 union all select 'abc',2 select * from @t
用于存储过程中:
--创建自定义类型,这里的自定义类型是表,可存储记录 CREATE TYPE MyTable AS TABLE ( a VARCHAR(50), b INT ) GO --drop proc proc_table --创建存储过程,传入参数为自定义表 CREATE Procedure dbo.proc_table (@ManyRows as MyTable readonly ) as select * from @manyrows go declare @t MyTABLE --可以直接把数据添加到LocationTableType类型中 --可以存储多条记录 insert into @t select '123',1 union all select 'abc',2 exec proc_table @t /* a b -------------------------------------------------- ----------- 123 1 abc 2 (2 行受影响) */
相关文章推荐
- 有趣的自定义类型:表
- .net: 怎么 让VS 识别自定义的文件类型?
- osg源码中的ref_ptr operator unspecified_bool_type() 指向类数据成员的指针&类转化为另一类型(如自定义的C类转化为int)
- 如何创建自定义的文件类型关联
- 【MyBatis学习16】自定义类型处理器typeHandlers介绍
- solr学习笔记 -- day04 导入数据、自定义类型
- 有趣的Java之包装类型的缓存与"==" equals
- SQL Server中修改“用户自定义表类型”问题的分析与方法
- OpenCms自定义结构化类型的高级设置
- struts2自定义类型转换器详解
- c#实现显式的用户自定义类型转换(关键字explicit operator)
- Oracle自定义函数解决数据类型转换出错的问题
- kubernetes1.5新特性:自定义资源类型
- jackson 枚举 enum json 解析类型 返回数字 或者自定义文字
- Struts2自定义类型转换器、自定义拦截器和用户输入数据的验证
- Geometry类型自定义类型转换器
- 统一绑定下拉框控件;设置同一类型的控件的属性;自定义错误处理类
- Activity中通过Bundle传递自定义数据类型
- Qt信号槽传递自定义类型参数
- std::set、自定义类型与比较函数