返回一个表的列信息
2014-03-19 17:21
197 查看
为了方便使用,可将其封装成一个函数代码如下:
--
-- 返回一个表的列信息
-- 用法:select * from tbl_columns('Table1')
-- zyl 2007.11.6
--
create function tbl_columns(@tablename nvarchar(256))
returns @tmptb table(
name nvarchar(256),
type varchar(256),
length int,
reallength int
)
begin
insert into @tmptb
select c.name, t.name as type, c.length
,(case t.name
when 'nvarchar' then c.length/2
when 'nchar' then c.length/2
else c.length
end)
as reallength
from syscolumns c join systypes t
on c.xtype=t.xtype
where t.name <> 'sysname' and c.id=object_id(@tablename)
return
end
这是一个运行结果:
--
-- 返回一个表的列信息
-- 用法:select * from tbl_columns('Table1')
-- zyl 2007.11.6
--
create function tbl_columns(@tablename nvarchar(256))
returns @tmptb table(
name nvarchar(256),
type varchar(256),
length int,
reallength int
)
begin
insert into @tmptb
select c.name, t.name as type, c.length
,(case t.name
when 'nvarchar' then c.length/2
when 'nchar' then c.length/2
else c.length
end)
as reallength
from syscolumns c join systypes t
on c.xtype=t.xtype
where t.name <> 'sysname' and c.id=object_id(@tablename)
return
end
这是一个运行结果:
相关文章推荐
- crazy proj : No 1 - design
- [极客]每个极客都应该知道的Linux技巧 (1)
- Linux命令缩写来由
- Python字符串格式化
- Flex与java简单的交互
- [软件工程] 查找二维数组最大子数组的之和 郭莉莉&李亚文
- 求二维整数数组最大子数组和
- 蓝桥杯 第三届C/C++预赛真题(7) 放棋子(水题)
- 学习:base64和图片。
- 一键u盘装系统 蓝屏
- 自我介绍先。。。。2014/3/9
- 面试常考的 group by +having 试题
- 某种序列(nyoj 114)
- HDU1007(解题报告)
- C#键盘事件处理父窗体子窗体
- 感觉差不多了。CLOUDSTACK的NAT,端口转发和防火墙结合穿透
- 敏捷开发---综述
- 两个PHP数组对比,计算新增了哪些值,删除了哪些值,共同拥有哪些值?
- 研究生阶段丢失的文件
- 法正(2):法雄