Click here to Skip to main content
15,910,980 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

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?
Posted
Comments
Zoltán Zörgő 6-Jan-13 8:03am    
You usually don't need a primary key for that. Actually it depends for what you want to "use" the result.

1 solution

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.
 
Share this answer
 
Comments
Espen Harlinn 6-Jan-13 9:13am    
Good reply :-D
Wendelius 6-Jan-13 10:57am    
Thank you Espen :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900