![]() | |
All SQL Workbench/J specific command can only be used from within SQL Workbench/J |
The command WbGenerateDelete can be used to generate a SQL script for one or more rows
that should be deleted including all rows from referencing tables (if foreign key constraints are defined)
This is also available through the menu item → which will generate the delete for the selected row(s) in the current result.
The command supports the following parameters.
| Parameter | Description |
|---|---|
| -table |
Specifies the root table of the hierarchy from which to delete the rows. It is possible to define multiple tables separated by a comma. The table names may contain wildcards. If multiple tables are specified, specifying a column value for the WHERE clause is not supported. |
| -columnValue |
Defines the expression for each PK column to select the rows to be deleted. The value for this parameter is the column name followed by a colon, followed by the value for this column or an expression.
e.g.:
You can also specify expressions instead:
For a multi-column primary key, specify the parameter multiple times:
This parameter is ignored if more than one table is specified with the |
| -includeCommit |
If |
| -outputFile |
The file into which the generated statements should be written. If this is omitted, the statements are displayed in the message area. |
| -appendFile |
Valid values:
If |
| -formatSql |
Valid values:
If |
To generate a script that deletes the person with ID=42 and all rows referencing that person, use the following statement:
WbGenerateDelete -table=person -columnValue="id:42";
To generate a script that deletes any person with an ID greater than 10 and all rows referencing those rows, use the following statement:
WbGenerateDelete -table=person -columnValue="id: > 10";
To generate a script that deletes rows from the film_category where the primary key consists of
the columns film_id and category_id:
WbGenerateDelete -table=person -columnValue="film_id: in (1,2,5)" -columnValue="category_id: in (7,3,5);
To generate a script that deletes rows from multiple tables in the correct order:
WbGenerateDelete -table=order*,customer*,invoice*;
The command WbGenerateInsert can be used to generate a SQL script that shows
the order in which INSERT statements should be executed with respect to declared foreign keys.
The command supports the following parameters.
| Parameter | Description |
|---|---|
| -tables |
Specify the list of tables for which the INSERT statements should be generated. |
| -retrieveFKParents |
If this is true, all parent tables for the tables specified by |
| -fullInsert |
If this is true the output will be complete |
| -file |
Specifies an output file to which the result is written instead of displaying it. |