trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sure...@apache.org
Subject [1/2] incubator-trafodion git commit: add identity column
Date Thu, 16 Feb 2017 16:54:06 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master c6b3873b4 -> 59025ccd9


add identity column


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/ec57afc2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/ec57afc2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/ec57afc2

Branch: refs/heads/master
Commit: ec57afc26b2e672aed53c9efc6d4f054886ea544
Parents: 60fcb54
Author: liu.yu <yu.liu@esgyn.cn>
Authored: Thu Feb 16 12:24:53 2017 +0800
Committer: liu.yu <yu.liu@esgyn.cn>
Committed: Thu Feb 16 12:32:49 2017 +0800

----------------------------------------------------------------------
 .../_chapters/sql_language_elements.adoc        | 78 +++++++++++++++++++-
 1 file changed, 77 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ec57afc2/docs/sql_reference/src/asciidoc/_chapters/sql_language_elements.adoc
----------------------------------------------------------------------
diff --git a/docs/sql_reference/src/asciidoc/_chapters/sql_language_elements.adoc b/docs/sql_reference/src/asciidoc/_chapters/sql_language_elements.adoc
index fde124d..b7fe71e 100644
--- a/docs/sql_reference/src/asciidoc/_chapters/sql_language_elements.adoc
+++ b/docs/sql_reference/src/asciidoc/_chapters/sql_language_elements.adoc
@@ -29,7 +29,7 @@
 {project-name} SQL language elements, which include data types, expressions, functions, identifiers,
literals, and
 predicates, occur within the syntax of SQL statements. The statement and command topics support
the syntactical
 and semantic descriptions of the language elements in this section.
-
+ 
 [[_authorization_ids]]
 == Authorization IDs
 
@@ -1872,6 +1872,82 @@ You can use reserved words as delimited identifiers. For example, table
 is not allowed as a regular identifier, but "table" is allowed as a
 delimited identifier.
 
+<<<
+[[identity_column]]
+== Indentity Column
+
+A identity column is an auto-increment column, which is defined to a column of a table with
identity attribute and used to automatically generate increasing or decreasing sequential
numeric value for a column with each row insertion into the table.
+
+Identity column, unlike a sequence which works independently of table column, is bound to
a table column and can be accessed only by the table column. For more information, see <<create_sequence_statement,CREATE
SEQUENCE Statement>>.
+
+```
+GENERATED [ALWAYS | BY DEFAULT] AS IDENTITY 
+[START WITH integer]
+[INCREMENT BY integer]
+[MAXVALUE integer | NOMAXVALUE]
+[MINVALUE integer]
+[CYCLE | NO CYCLE]
+[CACHE integer | NO CACHE]
+[DATA TYPE] 
+```
+
+[[syntax_description_of_identity_column]]
+=== Syntax Description of Indentity Column
+
+* `ALWAYS`
++
+Indicates that when a row is inserted to a table, a value will always be generated for the
column. 
+
+* `BY DEFAULT`
++
+Indicates that when a row is inserted to a table, if the value of the column is not specified,
then a default value will be assigned for the column. The value can be unique if you place
a unique index on the column.
+
+The options above serve the same purposes as they serve when you create a sequence. For more
information, see <<create_sequence_statement,CREATE SEQUENCE Statement>>.
+
+[[examples_of_identity_column]]
+=== Examples of Indentity Column
+
+* Example of `ALWAYS`
++
+```
+CREATE TABLE identity_employee (
+  id LARGEINT GENERATED ALWAYS AS IDENTITY,
+  description VARCHAR(40)
+);
+
+SQL>INSERT INTO identity_employee (description) VALUES ('Just DESCRIPTION');
+
+--- 1 row(s) inserted.
+
+SQL>INSERT INTO identity_employee (id, description) VALUES(NULL, 'ID=NULL and DESCRIPTION');
+
+*** ERROR[4122] NULL cannot be assigned to NOT NULL column TRAFODION.SEBASE.IDENTITY_EMPLOYEE.ID.
+
+SQL>INSERT INTO identity_employee (id, description) VALUES(999, 'ID=999 and DESCRIPTION');
+
+*** ERROR[3428] IDENTITY column ID defined as GENERATED ALWAYS cannot accept values specified
by the user.
+
+```
+* Example of `BY DEFAULT`
++
+```
+CREATE TABLE identity_employee (
+  id LARGEINT GENERATED BY DEFAULT AS IDENTITY,
+  description VARCHAR(40)
+);
+
+SQL>INSERT INTO identity_employee (description) VALUES ('Just DESCRIPTION');
+
+--- 1 row(s) inserted.
+
+SQL>INSERT INTO identity_employee (id, description) VALUES(NULL, 'ID=NULL and DESCRIPTION');
+
+*** ERROR[4122] NULL cannot be assigned to NOT NULL column TRAFODION.SEBASE.IDENTITY_EMPLOYEE.ID.
+
+SQL>INSERT INTO identity_employee (id, description) VALUES(999, 'ID=999 and DESCRIPTION');
+
+--- 1 row(s) inserted.
+```
 
 <<<
 [[indexes]]


Mime
View raw message