CREATE TABLE t ( auto UNSIGNED BIGINT DEFAULT GLOBAL AUTOINCREMENT ( 1000000000000000 ) ); INSERT t VALUES ( DEFAULT ); -- 1000000000000001 INSERT t VALUES ( DEFAULT ); -- 1000000000000002 INSERT t VALUES ( 1001 * 1000000000000000 ); -- 1001000000000000 INSERT t VALUES ( DEFAULT ); -- NULL
1.8.3 Literal Defaults
Simple literal DEFAULT values can be specified for string, numeric, and date/time columns. Here are some examples: CREATE TABLE t ( c1 INTEGER, c2 VARCHAR ( 1 ) DEFAULT 'Y', -- Y c3 BINARY ( 20 ) DEFAULT 0x48656C6C6F, -- Hello c4 VARCHAR ( 1 ) DEFAULT '\n', -- new line c5 VARCHAR ( 100 ) DEFAULT 'c:\\new', -- c:\new c6 LONG VARCHAR DEFAULT '\x61\x62\x63', -- abc c7 INTEGER DEFAULT 0, -- 0 c8 DECIMAL ( 9, 2 ) DEFAULT 27.95, -- 27.95 c9 DOUBLE DEFAULT -123.456E-2, -- -1.23456 c10 DATE DEFAULT '2003 07 06', -- July 6, 2003 c11 TIME DEFAULT '00:01', -- 1 minute past midnight c12 TIMESTAMP DEFAULT '20030706 14:30' ); -- 2:30 PM, July 6, 2003 SQL Anywhere offers several special literals for use in expressions and DEFAULT specifications. These literals are sometimes called special con- stants but they arent really constant; some of them change over time, others change to reflect the state of program execution. When used as DEFAULT val- ues, however, their values are frozen at the time they are copied to a row being inserted. <special_literal> ::= CURRENT DATABASE | CURRENT DATE | CURRENT TIME | CURRENT TIMESTAMP | CURRENT USER | CURRENT UTC TIMESTAMP | SQLCODE | SQLSTATE | USER The CURRENT DATABASE special literal returns the VARCHAR ( 128 ) run-time name of the database (e.g., 'test'). CURRENT DATE returns a DATE value containing todays date (e.g., 2003 06 11). CURRENT TIME returns a TIME value containing the current time (e.g., 10:16:40.940000). On some platforms the seconds may only contain two or three significant digits to the right of the decimal point. CURRENT TIMESTAMP returns a TIMESTAMP value containing the current date and time (e.g., 2003 06 11 10:16:40.940000). This DEFAULT can be used to answer the question When was this row inserted? On some plat- forms the seconds may only contain two or three significant digits to the right of the decimal point.