Tuesday, June 26, 2007

[SQL] Common Catalog Stored Procedures

1. sp_columns
Returns column information for the specified tables or views that can be queried in the current environment.

Example:

USE AdventureWorks
GO
EXEC sp_columns @table_name = N'Department',
@table_owner = N'HumanResources'


2. sp_tables
Returns a list of objects that can be queried in the current environment. This means any object that can appear in a FROM clause.

Example:
USE AdventureWorks;GOEXEC sp_tables @table_name = '%', @table_owner = 'Person', @table_qualifier = 'AdventureWorks'

3. sp_databases
Lists databases that either reside in an instance of the SQL Server 2005 Database Engine or are accessible through a database gateway.

Example:
USE master;
GO
EXEC sp_databases;

No comments: