Return the Parameters of a Stored Procedure or User-Defined Function in SQL Server (T-SQL Examples)

In SQL Server, you can use the Transact-SQL PARAMETERS system information schema view to find the parameters used in a stored procedure or user-defined function.

More specifically, it returns one row for each parameter of a user-defined function or stored procedure that can be accessed by the current user in the current database.

To use this view, specify the fully qualified name of INFORMATION_SCHEMA.PARAMETERS.

Continue reading

Find the Columns Returned by a Table-Valued Function (T-SQL Examples)

In SQL Server, you can use the Transact-SQL ROUTINE_COLUMNS system information schema view to find the columns returned by a table-valued function.

More specifically, it returns one row for each column returned by the table-valued functions that can be accessed by the current user in the current database.

To use this view, specify the fully qualified name of INFORMATION_SCHEMA.ROUTINE_COLUMNS.

Continue reading

Return Stored Procedures & Functions in a SQL Server Database: ROUTINES (T-SQL Examples)

In SQL Server, you can use the Transact-SQL ROUTINES system information schema view to return a list of stored procedures and functions in the current database.

More specifically, it returns a list of all stored procedures and functions that can be accessed by the current user in the current database.

You can also use ROUTINES simply to return information about a specific procedure or function if required.

To use this view, use the fully qualified name of INFORMATION_SCHEMA.ROUTINES.

Continue reading

How to Return a List of Data Types in SQL Server (T-SQL)

If you ever need to get a list of data types in SQL Server, you can use one of the system views to do just that.

In particular, you can use the sys.types system catalog view. This view returns all system-supplied and user-defined data types defined in the database. If you’re using SQL Server 2000 sys.systypes should do the trick.

Continue reading

How to Create a View in SQL Server

To create a view in SQL Server:

  1. Open a new query by clicking the New Query button in the SSMS toolbar
  2. Type or paste a CREATE VIEW statement (example below)
  3. Run the script

The view will now be created in the database. You will be able to see it under the Views node in the Object Explorer.

You can now use SELECT statements against the view in future queries.

Below are screenshots of the above steps.

Continue reading

What is a View?

In the world of databases, a view is a query that’s stored on a database.

The term can also be used to refer to the result set of a stored query.

To create a view, you write a query, then save it as a view.

To run a view, you query it, just like you’d query a table. The difference is that, the view itself is a query. So when you query the view, you’re effectively querying a query.  This enables you to save complex queries as views, then run simple queries against those views.

Continue reading