从返回表的函数中获取值 [英] Get a value from a function that returns table

查看:110
本文介绍了从返回表的函数中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我想声明一个变量并设置一个结果以下函数

Hello guys.
I want declare a variable and set one of results the following function

USE AdventureWorks
GO
CREATE FUNCTION UDF_TABLE_COLUMNS
(
   @SCHEMA VARCHAR(50),
   @TABLENAME VARCHAR(50)
   
)
RETURNS TABLE
AS
   RETURN
     SELECT COLUMN_NAME 
     FROM INFORMATION_SCHEMA.COLUMNS
     WHERE TABLE_NAME=@TABLENAME 
     AND TABLE_SCHEMA=@SCHEMA



系统视图INFORMATION_SCHEMA没有任何主键。

我怎么能使用该函数的一个值。

有没有索引或数组?


The system view INFORMATION_SCHEMA have not any primary key.
how can i use one of the values of the function.
Is there any index or array?

推荐答案

视图基本上没有主键,基础表有。另请注意,INFORMATION_SCHEMA不是视图,它是一个模式。该模式中的COLUMNS是一个视图。



您要查询的列视图是表中列的逻辑表示,因此如果您传递模式名称和表名作为参数和查询使用这些参数获得手头表的所有列。



SQL中的结果集没有任何索引器等。如果您将结果存储在数据表中,则可以使用索引器访问不同的行。但是,您没有解释为什么需要索引器。
Views basically never have a primary key, the underlying tables have. Also note that INFORMATION_SCHEMA is not a view, it''s a schema. The COLUMNS in that schema is a view.

The Columns view you''re querying is a logical representation of columns in tables so if you pass the schema name and the table name as a parameter and query using those parameters you get all the columns for the table at hand.

The result sets in SQL do not have any indexers etc. However if you store the results let''s say in a datatable, you can use indexer to access different rows. However, you didn''t explain why would you need an indexer.


这篇关于从返回表的函数中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆