Find invalid objects

You can use the Find Invalid Objects feature to identify invalid objects in databases. You can also automate the search for invalid objects from the command line.

An object is considered to be invalid when it references another object that doesn’t exist or is broken.

This topic explains how to find invalid objects in one or more databases, export the results to a .csv file, navigate to invalid objects in Database Explorer, and generate ALTER and DROP scripts. It also describes how to automate the search for invalid objects from the command line or schedule it using Windows Task Scheduler.

Find invalid objects in a database

1. Open the Find Invalid Objects document in one of these ways:

  • In Database Explorer, right-click the Database node and select Tasks > Find Invalid Objects.
  • On the Start Page, select Administration > Find Invalid Objects.
  • On the menu bar, select Database > Tasks > Find Invalid Objects.
  • Press Ctrl+Alt+F.

2. In Connection, select the connection.

3. Click the arrow next to Database and select the databases to search for invalid objects.

Tip

To reload a list of databases, click Refresh.

To select all databases, click Check All.

To clear the checkboxes next to all databases, click Uncheck All.

To filter a database list, in the search box, enter the search string. The matching text is highlighted in yellow.

Select the databases to search for invalid objects

4. Click Analyze.

The Find Invalid Objects document displays the result in:

  • The Find Invalid Objects grid – Lists invalid objects with such details as the object type, the schema the object belongs to, the object name, and the reason why it is considered invalid.
  • The Preview pane – Shows the SQL script generated for the selected invalid object. The invalid object is highlighted.

View invalid objects in the Find Invalid Objects document

Export invalid objects to a .csv file

You can export all invalid objects from the selected databases to a .csv file.

To export invalid objects to a .csv file:

1. Right-click the grid and select Export to CSV.

Export invalid objects to a .csv file

2. In the Save As dialog, specify the file name and select the folder to store the file.

3. Click Save.

The specified .csv file displays exported invalid objects in a grid format, including the same information from the Find Invalid Objects grid.

View the exported invalid objects

Navigate to invalid objects in Database Explorer

To navigate to an invalid object in Database Explorer, select a required object, right-click it, then select Find in Database Explorer.

Remove invalid objects from the grid

To remove all invalid objects from the grid, right-click the grid and select Clear All.

Generate scripts for invalid objects

You can generate ALTER and DROP scripts for selected invalid objects to a new SQL document or to the clipboard.

To generate a script:

1. In the Find Invalid Objects grid, select the checkbox for the object for which you want to generate a script.

2. To generate an ALTER script, on the toolbar, click the arrow next to Script as ALTER and select one of the following options:

  • To New SQL Window – Opens the script in a new SQL document.
  • To File – Saves the script to a .sql file.

View the generated ALTER script in a new SQL document

3. To generate a DROP script, on the toolbar, click the arrow next to Script as DROP and select one of the following options:

  • To New SQL Window – Opens the script in a new SQL document.
  • To File – Saves the script to a .sql file.

Tip

Clicking Script as ALTER or Script as DROP opens the script in a new SQL document.

The invalid object is marked with an error underline.

View the generated script with invalid objects marked with an error underline

Create a .bat file

You can create a .bat file with command-line settings, which you can then use for scheduling the automatic search for invalid objects in Windows Task Scheduler or any other task scheduler tool.

To create a .bat file:

1. On the toolbar, click Save Command Line.

2. In the command-line wizard, select the command-line settings you want to include in the file and specify the options.

The table provides options available in the command-line wizard.

Name Description
Connection Specifies the connection string.
Click the ellipsis (…) and select a connection or create a new one.
Password Specifies the server password and overrides the values from the /connection parameter.
Database Specifies one or more databases separated by a comma to find invalid objects.
All databases Indicates that the search will be performed in all databases hosted on the server.
Report Specifies a path to the report file to be generated in a CSV file format.
Click the ellipsis (…) and enter the file name in the required folder.
Log Specifies a path to a log file.
Click the ellipsis and enter the file name in the required folder.
Echo OFF Wraps all text in the .bat file within the @Echo OFF ... Echo ON block.
Keep opened Adds the pause command at the end of the script to keep the command window open after execution.
PowerShell Adds the & symbol at the beginning of the script to ensure PowerShell compatibility.

3. Optional: To verify the connection settings, click Validate.

4. Click Save.

Create a .bat file in the command-line wizard

Schedule the search for invalid objects

1. Open Task Scheduler.

2. Under Actions, click Create Basic Task to open Create Basic Task Wizard.

3. On the Create a Basic Task page, specify a name and an optional description for the task, then click Next.

Create a basic task

4. On the Trigger page, select a schedule, then click Next.

5. Depending on your selection, specify the start time, date, and the recurrence frequency, then click Next.

6. On the Action page, select Start a Program, then click Next.

7. Under Program/script, click Browse, select the .bat file, then click Next.

Create a basic task

8. On the Finish page, verify the settings.

9. Optional: To update the settings, click Back.

10. Click Finish.

Find invalid objects from the command line

You can automate the search for invalid objects in a database using the /findinvalidobjects parameter in the command line.

dbforgesql.com /findinvalidobjects [/option_name1[:value | [parameter1:value parameter2:value ..]] /option_name2 ..]

Command-line usage

The table describes arguments you can use with /findinvalidobjects in the command line.

Name Description
/findinvalidobjects Finds any invalid objects.
/connection Specifies the connection string.
Usage: /connection:<connection_string>
/password Specifies the server password and overrides the values specified in the /connection parameter.
Usage: /password:<password>
/database Specifies the databases and overrides the values specified in the /connection parameter. You can specify one or more databases separated by commas.
Usage: /database:<dbname1[,dbname2]>
/alldatabases Finds invalid objects for all non-system databases specified in the /connection parameter.
Usage: /alldatabases
/exitcodes Displays the list of exit codes returned by the command-line operation.
Usage: /exitcodes
/log Saves the generated log file to the specified folder.
Usage: /log:<filepath>
/report Generates a report in a CSV file format.
Usage: /report:<filename>
/treatwarningaserror Specifies the behavior for treating warnings.
Yes – Treats all warnings as errors, and the subsequent behavior will be determined by the errormode option.
No – Ignores warnings and continues executing the command-line script.
Usage: /treatWarningAsError:[Yes|No]
/errormode Specifies the application behavior when encountering an error:
ignore – Ignores all errors and continues script execution.
abort – Cancels script execution if an error occurs. Usage: /errormode:<ignore|abort>

Example: How to find invalid objects and create a CSV report

Let us find invalid objects in the AdventureWorks2025 database on the demo-mssql\SQL2025 server and generate a report in a CSV file format.

To find invalid objects:

1. To run dbForge Studio CLI commands, open Command Prompt and navigate to the folder that contains dbforgesql.com. The default path to this executable depends on where dbForge Studio for SQL Server is installed. If you installed dbForge Studio:

  • As a standalone tool
"C:\Program Files\Devart\dbForge Studio for SQL Server"
  • As part of the dbForge Edge bundle
"C:\Program Files\Devart\dbForge Edge\dbForge Studio for SQL Server"

2. Enter the /findinvalidobjects command. Replace the values with your actual data.

dbforgesql.com /findinvalidobjects /connection:"Data Source=demo-mssql\SQL2025; Integrated Security=False; User ID=sa; Password=yourPassword"; /database:AdventureWorks2025 /log:"D:\logfile.txt" /report:"D:\report.csv"

where:

  • AdventureWorks2025 is the name of the database whose invalid objects you want to find.
  • D:\logfile.txt is the path to the log file the operation creates after completion.
  • D:\report.csv is the path to the report file to be generated after completion.

3. Press Enter to execute the command.

The command outputs a table with invalid objects and generates log and report files.

Result

Log file

Generated log file

Report

Generated report