Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 table list

Author  Topic 

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2009-05-07 : 13:35:55
Does anyone know of a way to get a list of the tables included in a sql 2005 database? I have a database that has over 100 tables - some with very long names. I need a list of the tables that are included in the database. Any help would be greatly appreciated!

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-07 : 13:37:02
select [name] from sysobjects where xtype='u'
Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2009-05-07 : 13:41:32
This works, thanks.

I know there is about 100 tables in th db and this only shows 32. Do you know why?
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-07 : 13:43:19
100 including system tables ?
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-07 : 13:43:50
this would incude everything,
select [name] from sysobjects
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-07 : 13:44:48
you can even use information_SCHEMA.tables view

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-07 : 13:46:39
also to include views, you can add rows with xtype='v', xtype='s' for system tables
Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2009-05-07 : 13:47:29
quote:
Originally posted by sakets_2000

this would incude everything,
select [name] from sysobjects


Just user tables. I can see them, just don't want to have tpo type each one out!
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-07 : 13:52:39
then select [name] from sysobjects where xtype='u' or what viaskh gave you should list everything.
Go to Top of Page

chriztoph
Posting Yak Master

184 Posts

Posted - 2009-06-01 : 04:48:10
try this one

select * from sys.tables
Go to Top of Page
   

- Advertisement -