Dataverse - How you can more quickly bulk update data using the SQL language

When developing and testing apps with Dataverse, modifying and bulk-updating records can be difficult.

For example, deleting all records in a table or setting the value of multiple records based on a condition isn't straightforward.

If you're familiar with SQL, an easier option can be to install XrmToolBox and the SQL4CDS plugin and to issue SQL statements. 

What is XrmToolBox?

XrmToolbox is a free Windows application that allows users to connect to, manage, and customize Dataverse, Dynamics 365, and Power Platform solutions. From XrmToolbox, we can install plugins to carry out a wide range of tasks.

How to install XrmToolBox and SQL4CDS plugin

To install XrmToolbox, we visit the website below where we can download and install the latest version. There are more detailed instructions on how to perform through the XrmToolBox website.

https://www.xrmtoolbox.com/



Once XRMToolBox is installed, we open the Tool Library section. From here, we can search for and install the SQL 4 CDS plugin.


Creating a connection to Dataverse

XrmToolBox requires a connection to Dataverse which we setup by clicking the Connect button.

This process requires the 'Dynamics URL'. We can determine this by clicking the 'Advanced settings' menu item in the settings menu.


This opens the Dynamics 365 settings area in a new browser window, and the URL we use to connect is the first part of that address.


Using SQL4CDS to issue SQL Commands

Once SQL4CDS is installed, we can open a window as shown beneath. The object explorer view on the left-hand side shows all Dataverse tables beneath the 'entities' group.


From the toolbar, we configure the SQL4CDS settings as shown in the screenshot below.

Some notable settings include 'Use bulk delete operations' which improves the performance of bulk deletions. Beneath the 'Safety Limits' tab, we can prevent the execution of update or delete commands without a 'where' clause. This can help prevent the accidental update or deletion of all rows in a table.

Selecting records from a Dataverse table

We can issue a 'select' statement to return records from a table. We specify the logical Dataverse name so in this example, the logical name of an example table called Property is cr8a9_property1. A useful feature is that we can double-click table and field names in object explorer to insert the name into the editor. We click the 'execute' button to execute the query and the result appears in a grid as shown below.


We can also execute aggregate functions, such as the statement below to count the number of records in a table.

Updating all records in a Dataverse table

To highlight how to update all records in the property table, we issue the following SQL command.


UPDATE
cr8a9_property1
SET cr8a9_aquisitiondate = getdate()
WHERE 1=1
This command sets the 'acquisition date' field to today's date. The WHERE clause here is a hack that enables us to update all records in the table without enabling the 'prevent update without where' setting.

When we execute the command, SQL4CDS prompts for confirmation before it updates the records.


Deleting all records in a Dataverse table

To delete all records in a table, we can use issue a Delete statement like so:


DELETE FROM
cr8a9_property1
WHERE 1=1
Like before, SQL4CDS prompts for confirmation before it carries out the deletion.


Inserting records into a Dataverse table

It's also possible to insert records into a table by issuing an Insert command like so:

INSERT INTO
cr8a9_property1 (cr8a9_address1, cr8a9_address2)
VALUES
('10 High Street','London')
Here's the result that appears when we execute this command.


Conclusion

When building and testing apps, it can be very useful to modify Dataverse data using the SQL language. We can do this with the help of the SQL4CDS XRMToolBox plugin, and this post provided some examples of how this works.

Related posts

Dataverse - How to set yes no values with checkbox- Walkthrough
January 29, 2025
Dataverse - Add image column missing when creating table - how to fix
January 19, 2025
Data - How to view the progress and status of a Dataverse CSV/Excel Import
January 15, 2025
Error - Diagnosing the error "Network error when using the Patch function" when saving data with a form
May 05, 2024
Dataverse - How to work around the error "multiple levels of many-to-one relationship expansion aren't supported"
April 05, 2024
Dataverse - The easiest way to modify Dataverse data outside of Dataverse and Power Apps
February 18, 2024
Dataverse - How to use a checkbox control a set a yes/no field in Dataverse
July 10, 2023
Dataverse - How to create Entity Relationship diagrams
January 22, 2023
Dataverse - How to fix the bug in the 'Business Rules' editor that prevents numeric values from saving
January 05, 2023
Dataverse - What are the benefits, and how to create formula columns
July 20, 2022
Dataverse - How to sort the available choice items from a choice column
May 12, 2022
Error - Unable to modify Dataverse tables with error message, Language id should not be null
September 27, 2021
Dataverse - How to retrieve FetchXML or SQL for Dataverse views
July 13, 2021
Data - Why is Dataverse so fast?
June 15, 2021
Dataverse - How to create and use Dataverse views in Canvas Apps
June 09, 2021
Dataverse - How to filter Dataverse choice columns
June 07, 2021
Dataverse - How to switch to the classic designer when the option is not available
May 26, 2021
Licensing - What are Dataverse Restricted tables?
March 26, 2021
Media - How to save and work with microphone recordings
March 09, 2021
Dataverse - how to access tables from another environment
February 23, 2021
Dataverse - How to Patch the 5 most complex data types
January 19, 2021