How to find invalid objects
Last modified: March 28, 2025
dbForge Studio for SQL Server allows you to find invalid objects in multiple databases. The feature helps you learn if any objects have a reference to other objects that no longer exist or were modified. You can also automate the search for invalid objects in a database from the command line.
Find invalid objects in a database using the Studio
1. Open the Find Invalid Objects window by using one of the following ways:
- In Database Explorer, right-click the Database node and select Tasks > Find Invalid Objects.
- Go to the Administration tab of Start Page and select Find Invalid Objects.
- On the ribbon, select Database > Find Invalid Objects.
2. Specify the connection and select a database to search for invalid objects. In the Databases menu, you can:
- Check All to select all non-system databases available on the server.
- Uncheck All to clear the checkboxes next to all databases.
- Refresh the list of databases.
- Filter a database list by entering the text in the Search bar. The matching text will be highlighted in the list.
3. Click Analyze to start searching.
Invalid objects are listed in a grid showing the type of database object, the schema it belongs to, its name, and the reason why it is deemed invalid. The preview pane displays the SQL script generated for the invalid object and also highlights the object that caused the selected object to be invalid.
In the Find Invalid Objects window, you can perform the following tasks:
- Select the invalid objects to view the SQL script generated for the object at the bottom preview pane.
-
Right-click the invalid object and select on the shortcut menu:
- Clear All to remove all invalid objects from the grid.
- Find in Database Explorer to locate the selected invalid object in Database Explorer.
- Export to CSV to store data of all invalid objects as a grid in the CSV file. The grid contains the information available in the Find Invalid Objects window.
- Generate the ALTER and DROP scripts for the selected invalid objects to a new SQL document or clipboard.
- Create a .bat file to automate searching invalid objects from the command line.
Script out the object
1. In the Find Invalid Objects grid, select the checkbox next to the required object.
2. On the toolbar, click Script as ALTER to generate the ALTER script for the object or Script as DROP to generate the DROP script for the object.
Note
To copy the script to the clipboard, click the down arrow next to Script as ALTER or Script as DROP and select To Clipboard.
3. By default, the script will open in a new SQL document.
Create a .bat file
dbForge Studio for SQL Server has a built-in Command Line Wizard that converts the search options for invalid objects into command-line syntax and saves it as a *.bat file. You can then use this .bat file with a script and Windows Task Scheduler or any other task scheduler tool to schedule the search for invalid objects.
To open the Command Line Wizard, click Save Command Line on the toolbar.
Options of the Command Line Wizard
The command line wizard has the following options:
Option | Description |
---|---|
Connection | Specify the connection string for the database to search for invalid objects. |
Password | Specify the server password. Note that it will override the values specified in the Connection parameter. |
Database | Specify the database to find invalid objects. You can specify either a single database or multiple databases separated by commas. Note that it will override the database specified in the Connection parameter. |
All databases | Select this option if you want to search for invalid objects in all non-system databases located on the server. |
Report | Specify a path to the report that will be generated in the CSV file format. |
Log | Specify a path to a log file. |
Echo OFF | Select this option to enclose all the text in the bat file in the @Echo OFF … @Echo ON construct. This will turn off the display of the commands being entered on the screen. |
Keep opened | Select this option to place the pause command at the end of the bat file text. This will leave the command window open. |
PowerShell | Select this option to generate the & symbol at the beginning of the bat file text. This will ensure the PowerShell compatibility. |
You can click Validate to verify the script.
Find invalid objects in a database from the command line
You can automate the search for invalid objects in a database using the following script from the command line:
dbforgesql.com /findinvalidobjects [/option_name1[:value | [parameter1:value parameter2:value ..]] /option_name2 ..]
Command line usage
Argument | Action and usage |
---|---|
/findinvalidobjects |
Finds any objects referencing other objects that were dropped and no longer exist in the database. |
/connection |
Usage: /connection:<connection_string> Specifies the connection string. |
/password |
Usage: /password:<password> Specifies the server password and overrides the values specified in the /connection parameter. |
/database |
Usage: /database:<dbname1[,dbname2]> Specifies the database(s) and overrides the values specified in the /connection parameter. You can specify either a single database or multiple databases separated by commas. |
/alldatabases |
Usage: /alldatabases Finds invalid objects for all non-system databases specified in the /connection parameter. |
/exitcodes |
Usage: /exitcodes Displays the list of exit codes that the command-line operation can return. |
/log |
Usage: /log:<filepath> Generates a log file and saves it to the specified folder. |
/report |
Usage: /report:<filename> Generates a report in the CSV file format. |
/treatwarningaserror |
Usage: /treatWarningAsError:[Yes|No] Specifies the behavior for treating warnings. Yes : Treat all warnings as errors. The errormode option will determine the subsequent behavior. No : Do not consider warnings to be errors and continue the command line execution. |
/errormode |
Usage: /errormode:<ignore|abort> Specifies the application behavior when encountering an error:Ignore: Ignore all errors and continue execution.Abort: Cancel execution if an error occurs. |
Worked example: How to find invalid objects and create a CSV report
Let us find invalid objects in the AdventureWorks2022 database on the demo-mssql\SQLEXPRESS server and generate a report in the CSV file format.
To find invalid objects:
1. Open the Command Prompt or terminal and navigate to the installation folder of dbForge Studio for SQL Server. For this, you can use the cd
command. The default installation folder is C:\Program Files\Devart\dbForge Studio for SQL Server.
2. Enter the following command:
dbforgesql.com /findinvalidobjects /connection:"Data Source=demo-mssql\SQLEXPRESS; Integrated Security=False; User ID=sa"; /database:AdventureWorks2022 /log:"D:\logfile.txt" /report:"D:\report.csv"
where:
AdventureWorks2022
is a name of the database whose invalid objects you want to find.D:\logfile.txt
is a path to the log file the operation will create after completion.D:\report.csv
is a path to the report file the operation will generate after completion.
3. Press Enter to execute the command.
The command outputs a table with invalid objects and generates a log and report files.
Log file
Report
Download dbForge Studio for SQL Server and try it absolutely free for 30 days!
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.