Check Existence of Snapshot for a Database on SQL Server
SQL tutorial shows how to find if a database snapshot is already created for a specific SQL Server database. If you have high number of databases and your Database Snaphots node on SQL Server Management Studio is filled with numerous database snapshots, it is best to check if a snapshot of the database is created using SQL script.
As seen in below screenshot of SQL Server Management Studio (SSMS) Object Explorer window, under Database Snapshots node of target SQL Server instance there may be many databases making it difficult to search for a specific database snapshot.
Here is an example SQL script code where I query sys.databases system view for database properties for a sample database.
Assume that SQL programmer is trying to find out if a database snapshot is created for database named Kodyaz.
As seen above I join sys.databases to itself by using source_database_id and database_id column values.
The snapshot database when it is created refers to its original source database using the source_database_id field on sys.databases tables.
Here the snapshot database name and its source database is listed as a result of above SQL Select statement on sys.databases SQL Server system view
If you don't have a good naming convention, it might be difficult to find the source database for a snapshot database as well.
In such a case, you can reverse the above script and this time query for the source SQL database by using the snapshot database name as seen in below SQL code.