-- -- 返回一个表的列信息 -- 用法:select * from tbl_columns('Table1') -- zyl 2007.11.6 -- createfunction tbl_columns(@tablenamenvarchar(256)) returns@tmptbtable( name nvarchar(256), type varchar(256), length int, reallength int ) begin insertinto@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