18 July 2009

Sql for list all objects from Sql Server 2005 by re

I had been search on internet how can I list all object in sql server by sql commands. I found its sql as shown below :

SELECT name, CASE xtype WHEN 'C' THEN 'CHECK constraint' WHEN 'D' THEN 'Default or DEFAULT constraint' WHEN 'F' THEN 'FOREIGN KEY constraint ' WHEN 'L' THEN 'Log '
WHEN 'P' THEN 'Stored procedure '
WHEN 'PK' THEN 'PRIMARY KEY constraint (type is K) '
WHEN 'RF' THEN 'Replication filter stored procedure '
WHEN 'S' THEN 'System tables '
WHEN 'TR' THEN 'Triggers '
WHEN 'U' THEN 'User table '
WHEN 'UQ' THEN 'UNIQUE constraint (type is K) '
WHEN 'V' THEN 'Views '
WHEN 'X' THEN 'Extended stored procedure '
WHEN 'TF' THEN 'Functions'
END AS type
FROM dbo.sysobjects
ORDER BY type ASC


> List all database in your
SELECT * FROM sys.databases

> List all tables from specific database put it on before the tag 'sys.tables'
SELECT * FROM sys.tables
SELECT * FROM northwind.sys.tables
SELECT * FROM master.sys.tables