how Do I list all table names in SQL Server using T-SQL?

sql-server, sql-server-2005, t-sql

Solution

sp_msforeachdb 'select "?" AS db, * from [?].sys.tables'

Problem

``` SELECT name FROM sys.databases -- this can list all database name in the server user database SELECT * FROM INFORMATION_SCHEMA.TABLES -- these two line can list the table for one particular database ``` But how can I output the results like below? ``` Database Table --------- ------------- db1 t1 db1 t2 db2 t1 ... ... ```

Original source