Tuesday, December 1, 2009

Get database columns by using CTE

The following script uses Common Table Expression to get all columns in the database.
Applied to SQL Server 2005 or later

WITH DBColumns
AS
(
SELECT table_name, column_name
FROM [INFORMATION_SCHEMA].columns
)
SELECT table_name, column_name
FROM DBColumns

No comments:

Post a Comment