-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
CREATE PROCEDURE GETCOLUMNNAMES AS

DECLARE @tabname VARCHAR(32)
DECLARE @colname VARCHAR(32)

DECLARE c CURSOR FOR
SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE 't%'

OPEN c

FETCH NEXT FROM c INTO @tabname,@colname

WHILE @@FETCH_STATUS = 0
BEGIN
       PRINT @tabname + " " + @colname
       FETCH NEXT FROM c INTO @tabname,@colname
END

CLOSE c

DEALLOCATE c
GO
