Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

List Views In Database

Posted on February 25, 2013October 26, 2015 By David Kittell
SELECT
	name
FROM
	sys.views
ORDER BY
	name
SET NOCOUNT ON

DECLARE   @ViewName AS nVarChar(128)
        , @Query AS nVarChar(500)

/* Declare Cursor */
DECLARE Cur_Views CURSOR
    FOR
    SELECT  name
        FROM    [sys].[all_views] x
        WHERE   x.schema_id = 1

-- Loop through the views.
OPEN Cur_Views

-- Fetch the first view
FETCH NEXT FROM Cur_Views
    INTO      @ViewName

WHILE   @@Fetch_Status = 0 BEGIN
    -- Set up our dynamic sql
    SELECT  @Query = 'SELECT ''' + @ViewName + ''' AS Name, COUNT(*) AS [Count] FROM ' + @ViewName
    -- Print the query we're executing for debugging purposes
    -- PRINT @Query
    -- Execute the dynamic query
    EXECUTE(@Query)

    -- Fetch subsequent views
    FETCH NEXT FROM Cur_Views
        INTO      @ViewName

-- Loop back to the beginning
END -- WHILE    @@Fetch_Status = 0 BEGIN

-- Close the cursor
CLOSE Cur_Views

-- Dispose of the cursor
DEALLOCATE Cur_Views

GO
Originally Posted on February 25, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code MSSQL - Audit

Post navigation

Previous post
Next post

Related Posts

PowerShell – Install .NET 4.5.2

Posted on September 30, 2016

Configuration Net452Install { node "localhost" { LocalConfigurationManager { RebootNodeIfNeeded = $true } Script Install_Net_4.5.2 { SetScript = { $SourceURI = "https://download.microsoft.com/download/B/4/1/B4119C11-0423-477B-80EE-7A474314B347/NDP452-KB2901954-Web.exe" $FileName = $SourceURI.Split(‘/’)[-1] $BinPath = Join-Path $env:SystemRoot -ChildPath "Temp\$FileName" if (!(Test-Path $BinPath)) { Invoke-Webrequest -Uri $SourceURI -OutFile $BinPath } write-verbose "Installing .Net 4.5.2 from $BinPath" write-verbose "Executing $binpath /q…

Read More

Android Contacts – Remove Email Addresses

Posted on March 2, 2014October 26, 2015

DELETE FROM data WHERE mimetype_id IN ( SELECT _id FROM mimetypes WHERE mimetype LIKE "%email%" ) AND data1 LIKE ‘%@facebook.com%’; Originally Posted on March 2, 2014Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or program is…

Read More

Linux/Unix/Mac OSX – Find & Remove Empty Directories

Posted on May 4, 2016January 29, 2024

Occasionally you get empty directories and need to clear them out, these scripts below will help with that, just be careful what directory you choose. The scripts below are set to ~/ (current user home directory) but can easily be changed to any directory on your system. # List empty…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes