this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Tuesday, February 2, 2010

Query on schema of database

In sql server we create database object like tables, function, procedure etc. Some time we need to know how many tables or procedure are there.. at that time below sql query will be useful.

SQL provides query to execute on the object of itself.

List all the Database

SELECT * FROM sys.databases

SELECT * FROM master.dbo.sysdatabases

List all the tables in the Database

SELECT * FROM sysobjects WHERE type = 'U'

SELECT * FROM information_schema.tables

SELECT * FROM sys.tables

List all the Procedure in the Database

SELECT * FROM sys.procedures

SELECT * FROM sysobjects WHERE type = 'P'

List all the Function in the Database

SELECT * FROM sysobjects where type='fn'

Above syntax work correct in different version of sql server. Hope it will be useful.

No comments: