• Cursors, loops and dSQL fall under the last choice column but this is one of those cases...

    For tables you would do this:

    EXEC sp_MSforeachtable'SELECT TOP 1 * FROM ?'

    For views:

    SET NOCOUNT ON;

    GO

    IF OBJECT_ID('tempdb..#views') IS NOT NULL

    DROP TABLE #views;

    ;WITH views AS

    (SELECTROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS n,

    TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS)

    SELECT n, table_name

    INTO #views

    FROM views;

    GO

    --SELECT * FROM #views

    DECLARE @n int=1,

    @tbl varchar(100),

    @sql varchar(400)='SELECT TOP 1 * FROM ';

    WHILE @n<=(SELECT MAX(n) FROM #views)

    BEGIN

    SELECT @tbl=(SELECT TABLE_NAME FROM #views WHERE n=@n);

    EXEC('SELECT '''+@tbl+''' AS [THE TABLE]');

    EXEC(@sql+@tbl);

    SELECT @n=@n+1

    END

    DROP TABLE #views;

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001