SQL Server - Scroll each column in each table?

I have a business need that I have not seen in 10 or 15 years, so please excuse the dyno code that I will use to illustrate what I'm trying to do. I know there is a way to do something like this in SQL Server, it just was too darn for me.

In the days of MS DAO, I would use something like this to iterate over each field in each table. Ahh ... Memories ...

Dim dbs as DAO.Database
Dim tdf as DAO.TableDef
Dim fld as DAO.Field

For Each tdf in dbs.TableDefs
    For Each fld in tdf.Fields
        'Do whatever to every field in every table here.
    Next
Next

Can someone give me the equivalent of SQL Server?

EDIT : inside any loop structure that I can configure, I also need to specify the table name and field name (for example: tdf.Name and fld.Name). Thank!!!

EDIT 2 : FYI I will build SELECT statements from logic.

+5
1

:

SELECT s.name SchemaName, t.name TableName, c.name ColumnName
FROM sys.columns c INNER JOIN
     sys.tables t ON c.object_id = t.object_id INNER JOIN
     sys.schemas s ON t.schema_id = s.schema_id
;

(ADO.NET, LINQ ..).

+10

All Articles