![]() | |
All SQL Workbench/J specific command can only be used from within SQL Workbench/J |
WbGenerateScript
re-creates the SQL for objects in the database.
It is the command line version of the Generate Script option in the
DbExplorer
The command supports the following parameters.
Parameter | Description |
---|---|
-objects |
A comma separated list of table (views or other objects), e.g.
If this is not specified, all objects are included, i.e. it's equivalent to
The parameter supports auto-completion and will show a list of the available objects in the current schema. |
-exclude |
A comma separated list of object names to be excluded from the generated script.
The parameter supports wildcards |
-schemas |
A comma separated list of schemas. If this is not specified then the current (default) schema is used.
If this parameter is provided together with the The parameter supports auto-completion and will show a list of the available schemas. |
-types |
A comma separated list of object types e.g. The parameter supports auto-completion and will show a list of the available object types for the current DBMS. |
-file |
Defines the outputfile into which all statements are written. If this is not specified, the generated SQL statements are shown in the message area. file. |
-encoding |
The encoding to be used when writing the output file. |
-includeForeignKeys |
By default
The foreign keys can be generated in a separate step using the |
-includeTriggers |
If this parameter is is present (or set to true), then all triggers (for the selected schemas) will be retrieved as well.
The default is |
-includeProcedures |
If this parameter is present (or set to true), then all procedures and functions (for the selected schemas) will be retrieved as well.
The default is |
-includeDrop |
If this parameter is present (or set to true) a |
-includeTableGrants |
This parameter controls the generation of table grants. The default value is true .
|
-useSeparator |
If this parameter is present (or set to true), comments will be added that identify the start and end
of each object. The default is |
This command will show the source for a single table. The name of the table is given as an argument to the command:
WbTableSource person;
It is possible to provide wildcards for the table name:
WbTableSource p%;
This command is mainly intended to quickly look at a table's source, e.g. when running in console mode. To generate the DDL for multiple tables including depending objects or to save the generated SQL into a file, please use WbGenerateScript.
This command will show the source for a single view. The name of the view is given as an argument to the command:
WbViewSource current_orders;
The output of this command can be written to a file when using parameters:
WbViewSource -view=current_orders -file=/home/arthur/script/current_orders.sql;
The supported parameters are:
-view
- the name of the view-file
- the name of the output file-encoding
- the encoding to be used for the file
This command will show the source for a single stored procedure (if the current DBMS is supported by SQL Workbench/J). The name of the procedure is given as an argument to the command:
WbProcSource the_answer;
The output of this command can be written to a file when using parameters:
WbProcSource -procedure=the_answer -file=/home/arthur/scripts/answer_proc.sql;
The supported parameters are:
-procedure
- the name of the procedure (or package)-file
- the name of the output file-encoding
- the encoding to be used for the file
This command will show the source for a single trigger The name of the trigger is given as an argument to the command:
WbTriggerSource order_trigger;
The output of this command can be written to a file when using parameters:
WbTriggerSource -trigger=order_trigger -file=/home/arthur/scripts/order_trigger;
The supported parameters are:
-trigger
- the name of the trigger-file
- the name of the output file-encoding
- the encoding to be used for the file
The command WbGenerateDrop
can be used to generate a SQL script for a table that
will drop all foreign keys referencing that table, then a DROP
statement for that table
and the statements to re-created the foreign keys referencing that table.
This is useful if you need to re-create a table but don't want to manually delete all referencing foreign keys, especially if the DBMS does not support a cascading DROP.
This is also available in the DbExplorer's context menu as "Generate DROP script".
The command supports the following parameters.
Parameter | Description |
---|---|
-tables |
A comma separated list of tables, e.g. |
-includeCreate |
Valid values:
By default |
-onlyForeignkeys |
Valid values:
When using |
-sortByType |
Valid values:
Usually the generated SQL script will be ordered by the type of statements. So first all statements
to drop constraints will be listed, then the drop table statements, then the statements to re-create all foreign keys.
When specifying |
-outputFile |
Defines the file into which all statements are written. If multiple tables are selected
using the |
-outputDir |
Specifies an output directory into which one script per selected table will be written.
The script files are named |
If neither -outputFile
nor -outputDir
is specified, the output
is written to the message panel.
WbGenerateFKScript
re-creates the foreign key constraints for the specified tables.
The command supports the following parameters.
Parameter | Description |
---|---|
-tables |
The tables for which the foreign key constraints should be generated. This parameter accepts
wildcards, e.g. |
-exclude |
A comma separated list of tables names to be excluded from the generated script.
The parameter supports wildcards |
-file |
Defines the output file into which all statements are written. If this is not specified, the generated SQL statements are shown in the message area. file. |
-encoding |
The encoding to be used when writing the output file. |
WbGenerateImpTable
analyzes an import file and generates a suitable CREATE TABLE
statement to create a table with a structure that matches the import file, so that the file can be
imported into that table.
By default this command will only check the first 1000 lines of the input file, assuming that the values are distributed evenly. If the data types for the columns do not reflect the real data, the sample size needs to be increased.
The generated table definition is intended for a quick way to import the data and thus the column definitions are likely to be not completely correct or optimal.
The command supports the following parameters.
Parameter | Description |
---|---|
-file |
Specifies the input file to be analyzed. The filename may contain wildcards. When specifying
e.g.: |
-lines |
Defines the number of lines to analyze. The default is 1000 if this parameter is not specified A value of 0 (zero) or less, results in parsing the entire file. |
-type |
Possible values:
The type of the import file. The valid types are the same as for WbImport.
The To import spreadsheet files, the necessary additional libraries must be installed. |
-useVarchar |
Possible values:
If enabled, all columns will be created as
By default |
-delimiter | The delimiter for text files. |
-quoteChar | The quote character for text files. |
-encoding | The encoding for text files. |
-header | Specifies if the input file contains column headers. |
-dateFormat | The format for date columns. |
-timestampFormat | The format for timestamp columns in the input file. |
-decimal | The character used as the decimal separator. |
-outputFile |
By default the generated SQL statement is shown in the message area. If |
-sheetNumber |
If the input file is a spreadsheet, this parameter defines the sheet number to be analyzed.
The first sheet has the number
When specifying |
-table | The table name to use (or create) |
-runScript |
Possible values:
By default, the
By default, this will display a dialog to confirm the execution the |
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. |
-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:
|
-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);
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. |
-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. |