Monday, March 19, 2012

List Tables In A DataBase

hi everybody

If anybody knows how to list the tables in a database in Sql Server Query Analyser .

I would like to know is there any commands or SP 's like sp_help

Thank you for all the support

thanks & regards

Hi,

Simplest way would be to query the sysobjects table:

select name from sysobjects where xtype = 'U'

'U' = User table

Checkout sysobjects in BOL.

Jamie

|||

Another alternative is to use something more like:

SELECT table_name
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA ='dbo'
AND TABLE_TYPE ='BASE TABLE'

The advantage of this is that it does not use the system objects which are subject to change.

|||

Hi, nevincm

Code Snippet

select * from sysobjects where xtype = 'u' /*This will list all tables and its properties*/
select name from sysobjects where xtype = 'u' /*This will list table name as Jamie mentioned*/

Check this code

No comments:

Post a Comment