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
 General SQL Server Forums
 New to SQL Server Programming
 Print all tables in database

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2008-12-02 : 06:36:32
How can I print out all the tables in a database so that each is on a separate line?

I have:

use myDatabase
execute sp_MSforeachtable 'PRINT ''?'''

but I am not sure how to add the CR/LF

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-02 : 06:48:56
The PRINT command takes care of that!



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-02 : 06:50:09
Or you want a resultset with the table names?
SELECT	QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-02 : 06:56:28
if you want to exclude views,

SELECT	QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'
Go to Top of Page
   

- Advertisement -