|
| 1 | +# Quick SQL Grammar |
| 2 | + |
| 3 | +# Table of Contents |
| 4 | +1. [Datatypes](#datatypes) |
| 5 | +2. [Table Directives](#table-directives) |
| 6 | +3. [Column Directives](#column-Directives) |
| 7 | +4. [Views](#views) |
| 8 | +5. [Settings](#settings) |
| 9 | +6. [Grammar](#grammar) |
| 10 | + |
| 11 | + |
| 12 | +# Datatypes<a name="datatypes"></a> |
| 13 | +| Type | DB Type | |
| 14 | +| -------- | ------- | |
| 15 | +| num, number | NUMBER | |
| 16 | +| int, integer | INTEGER | |
| 17 | +| d, date | Date | |
| 18 | +| ts, timestamp | TIMESTAMP | |
| 19 | +| tstz, tswtz, timestamp with local time zone | TIMESTAMP WITH LOCAL TIMEZONE | |
| 20 | +| char, vc, varchar, varchar2, string | Varchar2(4000) | |
| 21 | +| vcNNN,vc(NNN) | Varchar2(NNN) | |
| 22 | +| vc32k | Varchar2(32767) | |
| 23 | +| clob | clob | |
| 24 | +| blob | blob | |
| 25 | +|json | CLOB CHECK (<Column Name> IS JSON) | |
| 26 | +| file | Adds a BLOB column and _FILENAME, _CHARSET, _MIMETYPE, _LASTUPD columns that enhance the ability for file download via a browser | |
| 27 | + |
| 28 | +# Table Directives<a name="table-directives"></a> |
| 29 | +| Directive | Description | |
| 30 | +| -------- | ------- | |
| 31 | +| /api | enerate PL/SQL package API to query, insert, update, and delete data within a table. Adds Oracle auditing, by default AUDIT ALL ON [TABLE NAME]. | |
| 32 | +| /audit | Adds Oracle auditing, by default AUDIT ALL ON [TABLE NAME].| |
| 33 | +| /auditcols, /audit cols, /audit columns | Automatically adds an UPDATED, UPDATED_BY, INSERTED, and INSERTED_BY columns and the trigger logic to set column values. | |
| 34 | +| /colprefix | Prefix all columns of a given table with this value. Automatically adds an underscore if not provided. | |
| 35 | +| /compress, /compressed | Table will be created compressed. | |
| 36 | +| /insert NN | Generate NN SQL INSERT statement(s) with random data, for example: /INSERT 20. (Maximum = 1000) | |
| 37 | +| /rest | Generate REST enablement of the table using Oracle REST Data Services (ORDS) | |
| 38 | +| /select | Generate SQL SELECT statement after generating data for each table | |
| 39 | +| /unique | Generate table level unique constraint | |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +# Column Directives<a name="column-directives"></a> |
| 44 | +| Directive | Description | |
| 45 | +| -------- | ------- | |
| 46 | +| /idx, /index, /indexed | Creates a non unique index | |
| 47 | +| /unique | Creates a unique constraint | |
| 48 | +| /check | Creates a check constraint with comma or white space delimited values e.g. /check Yes, No | |
| 49 | +| /constant | When generating data set this column to a constant value. For example /constant NYC. | |
| 50 | +| /default | Adds default value if the column is null | |
| 51 | +| /values | Comma separated list of values to use when generating data. For example /values 1, 2, 3, 4 or /values Yes, No. | |
| 52 | +| /upper | Forces column values to upper case | |
| 53 | +| /lower | Forces column values to lower case | |
| 54 | +| /nn, /not null | Adds a not null constraint on the column | |
| 55 | +| /between | Adds a between check constraint on the column, for example /between 1 and 100 | |
| 56 | +| /hidden, /invisible | Hidden columns are not displayed using select * from table. | |
| 57 | +| /references, /reference, /fk | Foreign key references e.g. /references table_name. Note you can reference tables that are not part of your model. | |
| 58 | +| /pk | Identifies column as the primary key of the table. It is recommended not manually specify primary keys and let this app create primary key columns automatically. | |
| 59 | +| --, [ comments ] | Enclose comments using square brackets or using dash dash syntax | |
| 60 | + |
| 61 | +# Views<a name="views"></a> |
| 62 | +### Syntax: |
| 63 | +`view [view_name] [table name] [table name]...` |
| 64 | + |
| 65 | +Ensure the view name contains no spaces, ensure the table names contain no spaces. Delimit table names by a space or comma. |
| 66 | +### Example: |
| 67 | +`dept dname loc emp ename job view dept_emp emp dept` |
| 68 | + |
| 69 | +This syntax restricts views to conjunctive queries (i.e. containing equijoin predicates) only. |
| 70 | + |
| 71 | +# Settings<a name="settings"></a> |
| 72 | + |
| 73 | +You can enter inline settings to explicitly set SQL syntax generation options. Alternatively, you can click Settings at the top of the right pane to |
| 74 | +declaratively set the generation options. |
| 75 | + |
| 76 | +Entering settings directly into the Quick SQL Shorthand pane ensures the same SQL generation options are utilized even if you download the script and later paste it back. For example, enter the following to prefix all table names with TEST and generate for schema OBE: |
| 77 | + |
| 78 | +`# settings = { prefix: "test", schema: "OBE" }.` |
| 79 | +Alternatively, enter each setting on a separate line for the same result: |
| 80 | + |
| 81 | +`# prefix: "test"` |
| 82 | + |
| 83 | +`# schema: "OBE"` |
| 84 | + |
| 85 | +Note: The settings must start on a new line and begin with # settings = to enter multiple settings, or # to enter a single setting per line. All values are case insensitive. Brackets, spaces, and commas can be added for clarity but are ignored. To have all settings generated use # verbose: true. |
| 86 | + |
| 87 | + |
| 88 | +#### ` # apex: true | false ` |
| 89 | +##### Default : false |
| 90 | +This setting controls the syntax generated to support audit columns. Specifically if audit columns are enabled triggers are generated to maintain the user creating a row and the user last updating a row. When enabled the following function is used: |
| 91 | + |
| 92 | +`coalesce(sys_context('APEX$SESSION','APP_USER'),user)` |
| 93 | + |
| 94 | +When not enabled the following function is used: `user` |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +#### `# api: true | false` |
| 99 | +##### Default : false |
| 100 | +Generate PL/SQL APIs on all tables for create, insert, update, delete and query. |
| 101 | + |
| 102 | +#### `# auditcols: true | false` |
| 103 | +##### Default : false |
| 104 | +Adds an additional created, created_by, updated and updated_by columns to every table created. |
| 105 | + |
| 106 | +#### `# compress: true | false` |
| 107 | +##### Default : false |
| 108 | +When enabled creates all tables compressed. |
| 109 | + |
| 110 | +#### `# createdByCol: "created_by_user"` |
| 111 | +##### Default : created_by |
| 112 | +When Audit Columns are enabled the default column used to track the user who created a row is CREATED_BY. Use this setting to override default audit column name. |
| 113 | + |
| 114 | +#### `# createdCol: "created_date"` |
| 115 | +##### Default : created |
| 116 | +When Audit Columns are enabled the default column used to track the user who created a row is CREATED. Use this setting to override default audit column name. |
| 117 | + |
| 118 | +#### `# date: "timestamp with local time zone"` |
| 119 | +##### Default : date |
| 120 | +By default all DATE columns created using the Oracle DATE datatype. Use this setting to override this default. Valid values are: |
| 121 | +date, timestamp, timestamp with time zone,TSWTZ, timestamp with local time zone, TSWLTZ. |
| 122 | + |
| 123 | +#### `# db: "19c"` |
| 124 | +##### Default : 21c |
| 125 | +Specifies the database version the syntax should be compatible with. Valid values are: **11g**, **12c**, **19c**, **21c** |
| 126 | + |
| 127 | +#### `# drop: true| false` |
| 128 | +##### Default : false |
| 129 | +Include SQL commands to drop each database object created. |
| 130 | + |
| 131 | +#### `# language: "EN"` |
| 132 | +##### Default : EN |
| 133 | +Generate data used for insert statements using this language. The default is English. Supported languages include: **EN**, **DE**, **KO**, **JA** |
| 134 | + |
| 135 | +#### `# longVC: true| false` |
| 136 | +##### Default : false |
| 137 | +Allow longer identifiers to be used for database object names. Longer identifiers allow the maximum length a VARCHAR2 column datatype will be 32767 characters. When not set the maximum length of a VARCHAR2 column datatype will be 4000 characters. |
| 138 | + |
| 139 | +#### `# ondelete: "cascade"` |
| 140 | +##### Default : false |
| 141 | +This setting controls how foreign key ON DELETE settings. Valid values include: **cascade**, **restrict**, **set null** |
| 142 | + |
| 143 | +#### `# overrideSettings: true| false` |
| 144 | +##### Default : false |
| 145 | +When enabled all application settings set via the user interface console are ignored and only settings set in the script will be used. |
| 146 | + |
| 147 | +#### `# PK: "identity"` |
| 148 | +##### Default : identity |
| 149 | +Determines how the primary key will be set. Primary keys can be set using SYS_GUID, identity column or sequence. Valid values include:**guid**, **seq**, **identity**, **none** |
| 150 | + |
| 151 | +#### `# prefix: "foo"` |
| 152 | +##### Default : |
| 153 | +Database object prefix. An underscore will be appended if not provided. |
| 154 | + |
| 155 | +#### `# prefixPKwithTname: true | false ` |
| 156 | +##### Default : false |
| 157 | +Prefix primary key database table columns with name of table. For example the primary key of the EMPLOYEE table would be EMPLOYEE_ID. Without setting the name of implicitly created primary key columns will be ID. |
| 158 | + |
| 159 | +#### `# genPK: true | false ` |
| 160 | +##### Default : true |
| 161 | +Prefix primary key database table columns with name of table. For example the primary key of the EMPLOYEE table would be EMPLOYEE_ID. Without setting the name of implicitly created primary key columns will be ID. |
| 162 | + |
| 163 | +#### `# resetsettings ` |
| 164 | +##### Default : |
| 165 | +Resets all application settings to default values. When included all application settings currently active for your session will be ignored. |
| 166 | + |
| 167 | +#### `# rowkey: true | false ` |
| 168 | +##### Default : false |
| 169 | +For each table created add a ROW_KEY column that generates an alphanumeric identifier. Values of the ROW_KEY column will be set by generated database table trigger logic. |
| 170 | + |
| 171 | +#### `# tenantID: true | false ` |
| 172 | +##### Default : false |
| 173 | +For each table add a TENANT_ID column to support mutil-tenant applications. The value of this column is simply added to the table, maintaining this value will need to be provided by the developer. |
| 174 | + |
| 175 | +#### `# rowVersion: true | false` |
| 176 | +##### Default : false |
| 177 | +For each table generated add a ROW_VERSION column that increments by 1 for each update. When enabled database table trigger logic will be generated to increment row versions on update. |
| 178 | + |
| 179 | +#### `# schema: "scott"` |
| 180 | +##### Default : |
| 181 | +Prefix object names with a schema name. The default is no schema prefix for object names. |
| 182 | + |
| 183 | +#### `# semantics: "char"` |
| 184 | +##### Default : |
| 185 | +You can choose no column semantics, or **BYTE** or **CHAR** semantics. |
| 186 | +Examples: |
| 187 | + |
| 188 | +`varchar2(4000), varchar2(4000 byte), varchar2(4000 char)` |
| 189 | + |
| 190 | + |
| 191 | +#### `# updatedByCol: "updated_by_user"` |
| 192 | +##### Default : updated_ by |
| 193 | +When enabling audit columns use this setting to override default audit column name. |
| 194 | + |
| 195 | +#### `# updatedCol: "updated_dt"` |
| 196 | +##### Default : updated |
| 197 | +When enabling audit columns use this setting to override default audit column name. |
| 198 | + |
| 199 | +#### `# verbose: true | false` |
| 200 | +##### Default : false |
| 201 | +Show all settings, not just settings that are different from the default. |
| 202 | + |
| 203 | + |
| 204 | +## Grammar<a name="grammar"></a> |
| 205 | +``` |
| 206 | + qddl::= stmt+ |
| 207 | +stmt::= tree |
| 208 | + | view |
| 209 | + | '#' individual_setting |
| 210 | + | 'settings' '=' '{' individual_setting ( ',' individual_setting )* '}' |
| 211 | +view::= 'view' view_name table_name+ |
| 212 | +view_name::= identifier |
| 213 | +table_name::= identifier |
| 214 | +column_name::= identifier |
| 215 | +tree::= node+ |
| 216 | +
|
| 217 | + tableNode::= indentation tableName tableDirective* |
| 218 | +columnNode::= indentation columnName columnDirective* datatype* |
| 219 | +indentation::= INDENT | DEDENT | SAMELEVEL |
| 220 | +tableDirective::= '/' |
| 221 | + ('api' |
| 222 | + |'audit'|'auditcols'|'audit cols'|'audit columns' |
| 223 | + |'colprefix' |
| 224 | + |'compress'|'compressed' |
| 225 | + |'insert' integer |
| 226 | + |'rest' |
| 227 | + |'select' |
| 228 | + |'unique' ) |
| 229 | +columnDirective::= '/' |
| 230 | + ('idx'|'index'|'indexed' |
| 231 | + |'unique' |
| 232 | + |'check' |
| 233 | + |'constant' |
| 234 | + |'default' |
| 235 | + |'values' |
| 236 | + |'upper' |
| 237 | + |'lower' |
| 238 | + |'nn'|'not null' |
| 239 | + |'between' |
| 240 | + |'hidden'|'invisible' |
| 241 | + |'references'|'reference' |
| 242 | + |'fk'|'pk' ) |
| 243 | +datatype::= |
| 244 | + 'num'|'number' |
| 245 | + |'int'|'integer' |
| 246 | + |'d'|'date' |
| 247 | + |'ts'|'timestamp' |
| 248 | + |'tstz'|'tswtz'|'timestamp' 'with' 'local' 'time' 'zonechar' |
| 249 | + |'vc'|'varchar'|'varchar2'|'string' |
| 250 | + |'vc' integer | 'vc' '(' integer ')' |
| 251 | + | 'vc32k' |
| 252 | + | 'clob'|'blob'|'jsonfile' |
| 253 | +individual_setting::= |
| 254 | + ( 'apex'|'api'|'audit' |
| 255 | + |'cols'|'compress'|'createdbycol'|'createdcol' |
| 256 | + |'date'|'db'|'drop' |
| 257 | + |'language'|'longvc' |
| 258 | + |'ondelete'|'overridesettings' |
| 259 | + |'pk'|'prefix'|'prefixpkwithtname' |
| 260 | + |'genpk' |
| 261 | + |'resetsettings'|'rowkey' |
| 262 | + |'tenantid'|'rowversion' |
| 263 | + |'schema'|'semantics' |
| 264 | + |'updatedbycol'|'updatedcolverbose' ) ':' (string_literal| 'true' | 'false') |
| 265 | +``` |
| 266 | + |
0 commit comments