RDB/VMS SQL CREATE — VMS SQLdev_2.0
Creates definitions for VAX SQL.
Additional information available:
DATABASEDOMAININDEXSCHEMASTORAGE_AREASTORAGE_MAP
TABLEVIEW
DATABASE
The CREATE DATABASE statement is supported only for upward compatibility. For information on creating databases see the Help topic on CREATE SCHEMA.
DOMAIN
CREATE DOMAIN -+
+--------------+
+-> domain-name IS data-type -+--------------------------+----+-> ;
| ++-> sql-and-dtr-clause -+-+ |
| +------- <--------------+ |
+-> FROM --> path-name --+----------------->---------------+--+
+-> SCHEMA AUTHORIZATION auth-id -+
Additional information available:
More Informationdata typeFROM clausesql and dtr clause
More Information
Creates a domain definition, which includes the domain name, a data type, and optional SQL and DATATRIEVE support clauses. The domain name must be unique among domain names in the database. When the CREATE DOMAIN statement executes, VAX SQL adds the domain definition to the physical database. If you declared the schema with the PATHNAME specification, the domain definition is also added to the data dictionary. Domains ensure that similar columns in multiple tables will comply to one standard. Once you have a defined domain, use the CREATE or ALTER TABLE statement to define many columns based on a domain definition. Domains also allow you to change the data type or SQL and DATATRIEVE parameters for all columns defined using a domain, simply by changing the domain itself.
data type
data-type = --+-> CHAR -+--------+---------------------------+--> | +-> (n) -+ | +-> VARCHAR (n) -------------------------------+ +-> LONG VARCHAR ------------------------------+ +-> SMALLINT --+-+--------+--------------------+ +-> INTEGER ---+ +-> (n) -+ | +-> QUADWORD --+ | +-> DECIMAL -+-+-----------------------------+-+ +-> NUMERIC -+ +-> ( --> n -+--------+-> ) --+ | | +-> , n -+ | +-> FLOAT -+--------+--------------------------+ | +-> (n) -+ | +-> REAL --------------------------------------+ +-> DOUBLE PRECISION --------------------------+ +-> DATE --------------------------------------+
FROM clause
The FROM clause specifies the data dictionary path name of a dictionary field definition. SQL creates the domain using the definition from this record. You can specify either a full data dictionary path name or a relative data dictionary path name. You cannot specify SQL and DATATRIEVE support clauses if you use the FROM path-name form of the CREATE DOMAIN statement.
Additional information available:
authorization id
The authorization identifier specifies the name for an attachment to a particular database. SQL adds the domain definition to the database referred to by the authorization identifier. If you do not specify an authorization identifier, SQL adds the domain definition to the default schema.
sql and dtr clause
sql-and-dtr-clause = -+-> QUERY HEADER IS -+> quoted-string --+-----------------+-> | +------ / <--------+ | +-> EDIT STRING IS quoted-string -------------------------+ | | +-> QUERY NAME FOR -+-> DTR --------+-> IS quoted-string -+ | +-> DATATRIEVE -+ | +-> DEFAULT VALUE FOR -+-> DTR --------+-> IS literal ----+ | +-> DATATRIEVE -+ | +-> NO QUERY HEADER --------------------------------------+ +-> NO EDIT STRING ---------------------------------------+ +-> NO QUERY NAME ----+--> FOR -+-> DTR --------+---------+ +-> NO DEFAULT VALUE -+ +-> DATATRIEVE -+ Optional formatting clauses allow you to modify data displays or query characteristics for interactive SQL users and DATATRIEVE users. A query header specifies a string that interactive SQL or DATATRIEVE displays in place of the column name when it retrieves values from a column. An edit string specifies a string that controls how interactive SQL or DATATRIEVE formats the display of values in a column. DEFAULT VALUE and QUERY NAME are active only from DATATRIEVE.
INDEX
CREATE -+-----------+-> INDEX index-name -+
+-> UNIQUE -+ |
+-----------------------------------------+
+-> ON table-name --> ( -+> column-name -+----------++-> ) -+
| +-> ASC ---+| |
+----------- , <------------+ |
+----------------------- <----------------------------------+
+-+----------------------------> -------------------------------+-+
+-> TYPE IS -+-> SORTED -+--------------------------------+-+-+ |
| +++-> NODE SIZE number-bytes --+++ | |
| |+-> PERCENT FILL percentage -+| | |
| |+-> USAGE -+-> UPDATE -+-----+| | |
| | +-> QUERY --+ | | |
| +--------------- <-------------+ | |
+-> HASHED ------------------------------------+ |
+-----------------------------------------------------------------+
+-+-----------------------+-> ;
+-> index-store-clause -+
Additional information available:
More Information
The CREATE INDEX statement defines an index for a base table. An
index allows direct access to the rows in the table to avoid
sequential searching.
You define an index by listing the columns in a table that make up
the index. You can define more than one index for a table. The
index can be either simple or multisegmented. A simple index is made
up of one column while a multisegmented index is made up of two or
more columns.
Optional arguments to CREATE INDEX let you specify:
o The characteristics of index nodes
o Whether the index is a hashed index or a B-tree index
o The names of a storage area or storage areas that will contain
the index
store clause
store-clause = STORE -+
+---------------------+
+-> IN area-name -------------------------------------------------+->
+-> RANDOMLY ACROSS -> ( -+-> area-name -+-> ) -------------------+
| +----- , <-----+ |
+-> USING -> ( -+-> column-name -+-> ) -+ |
+------ , <------+ | |
+--------------------------------------+ |
++-> IN area-name WITH LIMIT OF -> ( -+- literal -+-> ) -+-+ |
| +---- , <---+ | | |
+-------------------------- <---------------------------+ | |
+----------------------------------------------------------+ |
+-> OTHERWISE IN area-name --------------------------------------+
Additional information available:
More Information
The store_clause specifies a storage map definition for the index.
You can specify a store clause for indexes in a multifile schema
only. The STORE clause in a CREATE INDEX statement allows you to
specify which storage area files will be used to store the index
entries:
o All index entries can be associated with a single storage area
o Entries of an index can be randomly distributed among several
storage areas
o Index entries can be systematically distributed, or partitioned,
among several storage areas by specifying upper limits on the
values for a key in a particular storage area
If you omit the storage map definition, the default is to store all
the entries for an index in the main RDB$SYSTEM storage area.
SCHEMA
CREATE SCHEMA -+--------------------------++---------------------+-+
+-> AUTHORIZATION auth-id -++-> root-file-params -+ |
+------------------------------------------------------------------+
++------------------------++----------------------+-> ;
+-> storage-area-params -++-+-> schema-element -++
+--------- <--------+
Additional information available:
More Informationauthorization idroot file paramsstorage area params
schema element
More Information
The CREATE SCHEMA statement creates a schema. A schema is the
definitions that comprise a database. CREATE SCHEMA lets you specify
in a single SQL statement all data and privilege definitions for a
new schema (you can also add definitions to the schema later).
In its simplest form, CREATE SCHEMA at least creates database system
files, specifies their names, and determines the physical
characteristics of the database. Using the optional elements of
CREATE SCHEMA, you can also specify:
o Whether the database created with CREATE SCHEMA is multifile or
single-file. The presence or absence of a CREATE STORAGE AREA
statement in a CREATE SCHEMA statement is what determines whether
the schema is single-file or multifile.
o Values for various root file parameters.
o Values for storage area parameters.
o Any number of schema elements (CREATE statements or a GRANT
statement.
authorization id
AUTHORIZATION auth-id specifies the authorization identifier for the implicit schema declaration executed by CREATE SCHEMA. An authorization identifier is a name for a particular attachment to a schema. For more information see the Help topic on authorization-id.
root file params
root-file-params =
----+-+--------------------------> -------------------------------+-+-->
| +-> FILENAME file-spec -------------------------------------+ |
| +-> PATHNAME path-name -------------------------------------+ |
| +-> DBKEY SCOPE IS -+-> TRANSACTION -+----------------------+ |
| | +-> ATTACH ------+ | |
| +-> NUMBER OF USERS IS --> number-users --------------------+ |
| +-> NUMBER OF BUFFERS IS -----> number-buffers -------------+ |
| +-> NUMBER OF VAXCLUSTER NODES IS --> number-nodes ---------+ |
| +-> NUMBER OF RECOVERY BUFFERS IS ---> number-buffers ------+ |
| +-> BUFFER SIZE IS -----> buffer-blocks --> BLOCKS ---------+ |
| +-> SNAPSHOT IS ----+-----> ENABLED -+-> IMMEDIATE --+-+--+ |
| | | +-> DEFERRED ----+ | | |
| | +-----> DISABLED ----------->--------+ | |
| +-> DICTIONARY IS ---+---> REQUIRED -------+----------------+ |
| | +---> NOT REQUIRED ---+ | |
| +-> ADJUSTABLE LOCK GRANULARITY IS -+-> ENABLED --+---------+ |
| | +-> DISABLED -+ | |
| +-> SEGMENTED STRING STORAGE AREA IS area-name -------------+ |
+------------------------------ <-------------------------------+
Additional information available:
More Information
Root file parameters are parameters that control the characteristics of the database root file associated with the schema, or characteristics stored in the root file that apply to the entire database. You can specify these parameters for either single-file or multifile databases. Root file parameters specified in CREATE SCHEMA cannot be changed with the ALTER SCHEMA statement. To change the root file parameters, you must use the EXPORT and IMPORT statements in the RDO utility of Rdb/VMS.
storage area params
storage-area-params = -+-+-------------------------->-----------------------------+-+--> | +-> ALLOCATION IS ---> number-pages ----> PAGES ---------+ | | +-> PAGE SIZE IS ----> page-blocks -----> BLOCKS --------+ | | +-> PAGE FORMAT IS --+----> UNIFORM ----+----------------+ | | | +----> MIXED ------+ | | | +-> THRESHOLDS ARE ( val1 -+----------------------+-> ) -+ | | | +-> ,val2 -+----------++ | | | | +-> ,val3 -+ | | | +-> INTERVAL IS -------> number-data-pages --------------+ | | +-> EXTENT IS ----+--> extent-pages ----> PAGES ----+----+ | | | +--> (extension-options)----------+ | | | +-> SNAPSHOT FILENAME ---> file-spec --------------------+ | | +-> SNAPSHOT ALLOCATION IS --> snp-pages --> PAGES ------+ | | +-> SNAPSHOT EXTENT IS -+-> extent-pages --> PAGES -+----+ | | +-> (extension-options) ----+ | +-------------<-------------------------------------<--------+
Additional information available:
More Informationextension options
More Information
Storage area parameters are parameters that control the
characteristics of database storage area files. You can specify most
storage area parameters for either single-file or multifile
databases, but the effect of the clauses differs:
o For single-file databases, the storage area parameters specify
the characteristics for the single storage area in the schema
o For multifile databases, the storage area parameters specify a
set of default values for any storage areas created by the CREATE
SCHEMA statement that do not specify their own values for the
same parameters. The default values apply to the RDB$SYSTEM
storage area, plus any others named in CREATE STORAGE AREA schema
elements.
CREATE STORAGE AREA clauses within the CREATE SCHEMA statement
can override these default values.
extension options
extension-options = --> ( MINIMUM OF min-pages PAGES, -+ +----------------------------------+ +-> MAXIMUM OF max-pages PAGES, + +-------------------------------+ +-> PERCENT GROWTH IS growth ) -->
Additional information available:
More Information
Extension options are useful for exercising greater control over the size and growth of an extent or snapshot extent when the 100 page default is not desired. Extension options are particularly useful with multivolume databases. Extension options include the MIN, MAX, and PERCENT parameters. If you use the MIN, MAX, and PERCENT parameters, you must enclose them in parentheses: (MINIMUM OF min-pages PAGES, MAXIMUM OF max-pages PAGES, PERCENT GROWTH IS growth). MINIMUM OF min-pages PAGES specifies the minimum number of pages of each extent. The default is 100 pages. MAXIMUM OF max-pages PAGES specifies the maximum number of pages of each extent. The default is 10,000 pages. PERCENT GROWTH IS growth specifies the percent growth of each extent. The default is 20 percent growth.
schema element
schema-element = -+-> create-storage-area-clause ---+-> +-> create-storage-map-statement -+ +-> create-domain-statement ------+ +-> create-table-statement -------+ +-> create-index-statement -------+ +-> create-view-statement --------+ +-> grant-statement --------------+
Additional information available:
More Information
A schema element is a CREATE STORAGE AREA clause, any CREATE statement or a GRANT statement: o CREATE STORAGE AREA clause o CREATE STORAGE MAP statement o CREATE DOMAIN statement o CREATE TABLE statement o CREATE INDEX statement o CREATE VIEW statement o GRANT statement
STORAGE_AREA
CREATE STORAGE AREA --+-> area-name --++-----------------------+-+
+-> RDB$SYSTEM -++-> FILENAME file-spec -+ |
+----------------------------------------------------------------+
++------------------------+-> ;
+-> storage-area-params -+
Additional information available:
More Informationstorage area params
More Information
You cannot issue CREATE STORAGE AREA as an independent statement. It is a clause allowed as part of a CREATE SCHEMA or IMPORT statement. The CREATE STORAGE AREA clause creates additional storage areas in a multifile schema. A storage area is data and snapshot files that are associated with particular tables in a multifile schema. A CREATE STORAGE AREA clause specifies the names for the storage area files and determines their physical characteristics. Subsequent CREATE STORAGE MAP statements actually associate the storage area with particular tables in the schema.
storage area params
storage-area-params = -+-+-------------------------->-----------------------------+-+--> | +-> ALLOCATION IS ---> number-pages ----> PAGES ---------+ | | +-> PAGE SIZE IS ----> page-blocks -----> BLOCKS --------+ | | +-> PAGE FORMAT IS --+----> UNIFORM ----+----------------+ | | | +----> MIXED ------+ | | | +-> THRESHOLDS ARE ( val1 -+----------------------+-> ) -+ | | | +-> ,val2 -+----------++ | | | | +-> ,val3 -+ | | | +-> INTERVAL IS -------> number-data-pages --------------+ | | +-> EXTENT IS ----+--> extent-pages ----> PAGES ----+----+ | | | +--> (extension-options)----------+ | | | +-> SNAPSHOT FILENAME ---> file-spec --------------------+ | | +-> SNAPSHOT ALLOCATION IS --> snp-pages --> PAGES ------+ | | +-> SNAPSHOT EXTENT IS -+-> extent-pages --> PAGES -+----+ | | +-> (extension-options) ----+ | +-------------<-------------------------------------<--------+ Storage area parameters control the characteristics of database storage area files.
STORAGE_MAP
CREATE STORAGE MAP map-name FOR table-name --+ +--------------------------------------------+ +-+-+-> store-clause ---------------------+-+-> ; | +-> PLACEMENT VIA INDEX index-name ---+ | | +-+-> ENABLE --+-> COMPRESSION -------+ | | +-> DISABLE -+ | +------------------- <--------------------+
Additional information available:
More Information
Associates a table with one or more storage areas. CREATE STORAGE
MAP specifies a storage map that controls which rows of a table are
stored in which storage areas.
In addition to creating storage maps, CREATE STORAGE MAP has options
that control:
o Which index the database system uses when inserting rows in the
table
o Whether the rows of the table will be stored in a compressed
format
store clause
store-clause = STORE -+
+---------------------+
+-> IN area-name -------------------------------------------------+->
+-> RANDOMLY ACROSS -> ( -+-> area-name -+-> ) -------------------+
| +----- , <-----+ |
+-> USING -> ( -+-> column-name -+-> ) -+ |
+------ , <------+ | |
+--------------------------------------+ |
++-> IN area-name WITH LIMIT OF -> ( -+- literal -+-> ) -+-+ |
| +---- , <---+ | | |
+-------------------------- <---------------------------+ | |
+----------------------------------------------------------+ |
+-> OTHERWISE IN area-name --------------------------------------+
Additional information available:
More Information
The STORE clause specifies the storage map definition. The STORE
clause in a CREATE STORAGE MAP statement allows you to specify which
storage area files will be used to store rows from the table:
o All rows of a table can be associated with a single storage area
o Rows of a table can be randomly distributed among several storage
areas
o Rows of a table can be systematically distributed, or
partitioned, among several storage areas by specifying upper
limits on the values for a column in a particular storage area
If you omit the storage map definition, the default is to store all
the records for a table in the main RDB$SYSTEM storage area.
TABLE
CREATE TABLE-+
+------------+
+-> table-name -> ( -++-> col-definition ---++-> ) ----------+-> ;
| |+-> table-constraint -+| |
| +---------- , <---------+ |
+-> FROM --> path-name --+----------------->---------------+-+
+-> SCHEMA AUTHORIZATION auth-id -+
Additional information available:
More Informationcol definitionFROM clausetable constraint
More Information
The CREATE TABLE statement defines a base table, its columns, constraints, and rows. The table definition is added to the database file and, if the schema was declared by path name, to the data dictionary. The CREATE TABLE statement also creates a default access control list (ACL) for the table.
col definition
col-definition =
--> column-name -+-> data-type ---+++---------->-------------++->
+-> domain-name -+|+-> col-constraint ------+|
|+-> sql-and-dtr-clause --+|
+-----------<--------------+
col-constraint =
-+------>------------------------+-+-------------------------------+->
+-> NOT NULL -------------------+ +-> DIAGNOSTIC constraint-name -+
+-> NOT NULL UNIQUE ------------+
+-> CHECK (predicate) ----------+
Additional information available:
More Informationdata typesql and dtr clause
More Information
The column definition specifies a data type or domain name and optional column-constraints and SQL and DATATRIEVE formatting clauses for the column specified by the column name.
data type
data-type = --+-> CHAR -+--------+---------------------------+--> | +-> (n) -+ | +-> VARCHAR (n) -------------------------------+ +-> LONG VARCHAR ------------------------------+ +-> SMALLINT --+-+--------+--------------------+ +-> INTEGER ---+ +-> (n) -+ | +-> QUADWORD --+ | +-> DECIMAL -+-+-----------------------------+-+ +-> NUMERIC -+ +-> ( --> n -+--------+-> ) --+ | | +-> , n -+ | +-> FLOAT -+--------+--------------------------+ | +-> (n) -+ | +-> REAL --------------------------------------+ +-> DOUBLE PRECISION --------------------------+ +-> DATE --------------------------------------+
sql and dtr clause
sql-and-dtr-clause = -+-> QUERY HEADER IS -+> quoted-string --+-----------------+-> | +------ / <--------+ | +-> EDIT STRING IS quoted-string -------------------------+ | | +-> QUERY NAME FOR -+-> DTR --------+-> IS quoted-string -+ | +-> DATATRIEVE -+ | +-> DEFAULT VALUE FOR -+-> DTR --------+-> IS literal ----+ | +-> DATATRIEVE -+ | +-> NO QUERY HEADER --------------------------------------+ +-> NO EDIT STRING ---------------------------------------+ +-> NO QUERY NAME ----+--> FOR -+-> DTR --------+---------+ +-> NO DEFAULT VALUE -+ +-> DATATRIEVE -+ Optional formatting clauses allow you to modify data displays or query characteristics for interactive SQL users and DATATRIEVE users. A query header specifies a string that interactive SQL or DATATRIEVE displays in place of the column name when it retrieves values from a column. An edit string specifies a string that controls how interactive SQL or DATATRIEVE formats the display of values in a column. DEFAULT VALUE and QUERY NAME are active only from DATATRIEVE.
FROM clause
The FROM clause specifies the data dictionary path name of a dictionary record definition. SQL creates the table and all associated columns using the definition from this field. You can specify either a full data dictionary path name or a relative data dictionary path name. You cannot specify support clauses for SQL or DATATRIEVE or constraints if you use the FROM path-name form of the CREATE TABLE statement.
Additional information available:
authorization id
A name for an attachment to a particular database. SQL adds the table definition to the database referred to by the authorization identiier. If you do not specify an authorization identifier, SQL adds the table definition to the default schema.
table constraint
table-constraint =
-+-> UNIQUE (-+-> column-name -+-> ) -+-+
| +----- , <-------+ | |
+-> CHECK (predicate) ---------------+ |
+------------------------------------+
+-+-------------------------------+->
+-> DIAGNOSTIC constraint-name -+
Additional information available:
More Information
A table-constraint is a constraint definition that applies to the whole table. There are two types of table constraints, UNIQUE and CHECK and an optional DIAGNOSTIC constraint name. The UNIQUE table constraint specifies that the combination of values for the columns named must be unique in a row. Columns named in the list must be defined with the NOT NULL column constraint. The CHECK table constraint specifies a predicate that column values inserted into the table must satisfy. Predicates in CHECK table constraints can refer to any column in the table. Column select expressions within the predicate can refer to other tables in the schema. Select More_Information to continue.
Additional information available:
More Information
The optional DIAGNOSTIC constraint-name specifies a name for a column
or table constraint that is used in several ways:
o The INTEG_FAIL error message specifies the name when an INSERT,
UDPATE, or DELETE statement violates the constraint
o ALTER TABLE DROP CONSTRAINT statements specify the name to drop a
table constraint
o SHOW TABLE statements display the names of column and table
constraints
VIEW
CREATE VIEW --> view-name ---+
+--------------------------+
++------------------------>-------------------------------------+-+
+-> ( -+-> column-name --+-+--------------->--------+-+-+-> ) -+ |
| | +-> sql-and-dtr-clause --+ | | |
| +---------<------------------+ | |
+---------------- , <----------------------------+ |
+-----------------------------------------------------------------+
+-> AS select-expr --> ;
Additional information available:
More Informationselect exprsql and dtr clause
More Information
The CREATE VIEW statement defines a view. A view is a table whose data is not physically stored. Rather, a view is a virtual structure that refers to rows stored in other tables. When the CREATE VIEW statement executes, it adds a view definition to the schema and, if the schema was declared by path name, to the data dictionary. The CREATE VIEW statement also creates a default access control list (ACL) for the view. Select More_Information to continue.
Additional information available:
More Information
Do not refer to read-only views in INSERT, UPDATE, or DELETE
statements. SQL considers as read-only views those with select
expressions that:
o Use the DISTINCT argument to eliminate duplicate rows from the
result table
o Name more than one table or view in the FROM clause
o Specify a subquery in the predicate of the WHERE clause
o Include a function in the select list
o Contain a GROUP BY or HAVING clause
select expr
select-expr =
SELECT -+------>------+-> select-list --+
+-> ALL ------+ |
+-> DISTINCT -+ |
+------------------------------<------+
+ FROM -++-> table-name -+-+----->----+-+-+--------->----------+-+
|+-> view-name --+ +-> alias -+ | +-> WHERE predicate -+ |
+---------- , <-----------------+ |
+------------------------------<---------------------------------+
++------------->------------------+-+---------->----------+-->
+-> GROUP BY -+-> column-name -+-+ +-> HAVING predicate -+
+------- , <-----+
Additional information available:
More Information
A select expression is an expression that defines which columns and rows of which tables SQL includes in the view. The select expression can name only tables in the same database as the view.
sql and dtr clause
sql-and-dtr-clause = -+-> QUERY HEADER IS -+> quoted-string --+-----------------+-> | +------ / <--------+ | +-> EDIT STRING IS quoted-string -------------------------+ | | +-> QUERY NAME FOR -+-> DTR --------+-> IS quoted-string -+ | +-> DATATRIEVE -+ | +-> DEFAULT VALUE FOR -+-> DTR --------+-> IS literal ----+ | +-> DATATRIEVE -+ | +-> NO QUERY HEADER --------------------------------------+ +-> NO EDIT STRING ---------------------------------------+ +-> NO QUERY NAME ----+--> FOR -+-> DTR --------+---------+ +-> NO DEFAULT VALUE -+ +-> DATATRIEVE -+ Optional formatting clauses allow you to modify data displays or query characteristics for interactive SQL users and DATATRIEVE users. A query header specifies a string that interactive SQL or DATATRIEVE displays in place of the column name when it retrieves values from a column. An edit string specifies a string that controls how interactive SQL or DATATRIEVE formats the display of values in a column. DEFAULT VALUE and QUERY NAME are active only from DATATRIEVE.