Andyblg's Blog

September 9, 2009

List All Tables, Columns of Database (SQL SERVER 2005)

Filed under: Script — andyblg @ 15:59
Tags: , ,

1. This will display the list of table in the database:

select * from [NameOfYourDatabase].sys.tables

select* from [NameOfYourDatabase].information_schema.tables

select * from sysobjects where type=’u’ (or) select * from sysobjects where xtype=’u’

select * from sys.objects WHERE type =’u’

select * from [NameOfYourDatabase].sys.objects where type =’u’

2. This will display the list of  column, type, length of each table in database:

use [NameOfYourDatabase]
select sysobjects.[name] as tablename
, syscolumns.[name] as columnname
, systypes.[name] as datatype
, syscolumns.[length] as length
from sysobjects
inner join syscolumns on sysobjects.[id] = syscolumns.[id]
inner join systypes on systypes.[xtype] = syscolumns.[xtype]
where sysobjects.[type] = ‘u’
order by sysobjects.[name]

3. Query to fetch all tables in all databases:

sp_msforeachdb @command1 = “USE [?]; SELECT DB_NAME()DATABASE_NAME, NAME FROM SYS.Tables”

sp_msforeachdb @command1 = “USE ?;select ‘?’,name,type from sys.objects where type = ‘U’ and name not like ‘dt%’ and name not like ‘#%’ order by 2”


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: