-- Collection of code snippets by Arne Vajhøj 
-- posted to eksperten.dk, usenet and other places (2002-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
