SansSQL

Friday, July 11, 2008

UnDocumented stored proc to find the primary key and foreign key Constraints defined on a table

EXEC sp_MStablekeys @TableName

sp_MStablekeys is an undocumented stored procedure to find all the primary keys and foreign keys defined on a particular table in SQL 2000 and SQL 2005.
This Stored procedure accepts a parameter @TableName and gives the primary keys and foreign keys defined on a that table.

UnDocumented stored proc to find the Check Constraints used in a table

EXEC sp_MStablechecks TableName

sp_MStablechecks is an undocumented Stored Procedure in SQL 2000 and SQL 2005 which helps in finding the various Check constraints used in a particular table. This stored proc accepts a parameter TableName and gives the various check constraints used in that table.

UnDocumented stored proc to find the Table references.

EXEC sp_MStablerefs Table_Name

sp_MStablerefs is an undocumented Stored procedure in SQL 2000 and SQL 2005 to find the referenced tables of the given table (Table name passed to the SP).

Tuesday, July 8, 2008

Stored Procedure to find Primary keys and foreign keys of a table.

Here are the Stored Procedures to find the Primary keys and Foreign keys of a table.

1. SP to find Primary keys on a particular table

EXEC sp_pkeys 'Table_Name'

2. SP to find Foreign keys on a particular table

EXEC sp_fkeys 'Table_Name'

Tuesday, July 1, 2008

Recovery model and status of all databases

SELECT name,
DATABASEPROPERTYEX(name, 'Recovery') as [Recovery Model],
DATABASEPROPERTYEX(name, 'Status') as Status
FROM master.dbo.sysdatabases
ORDER BY 1

Use this query to get the recovery model and status of all the databases present in the server.

OR

EXEC sp_msforeachdb 'Select databasepropertyex(''?'', ''recovery'')as ''Recovery Model of ? Database'''

To find only the recovery model of all the databases.

Ads