Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Data may be copied between tables even if they have different schema.
Here is an example where t1.key_1 is converted to VARCHAR and placed in
t2.col_3, t1.non_key_1 is copied into t2.col_2, and all the other columns of t2
are assigned their default values:
CREATE TABLE t1 (
key_1 INTEGER NOT NULL,
non_key_1 VARCHAR ( 100 ) NOT NULL,
PRIMARY KEY ( key_1 ) );
CREATE TABLE t2 (
key_col INTEGER NOT NULL DEFAULT AUTOINCREMENT,
col_2 VARCHAR ( 100 ) NOT NULL,
col_3 VARCHAR ( 100 ) NOT NULL,
updated_by VARCHAR ( 128 ) NOT NULL DEFAULT LAST USER,
last_updated TIMESTAMP NOT NULL DEFAULT TIMESTAMP,
PRIMARY KEY ( key_col ) );
Tip: Watch out for problems caused by implicit data conversions when values
are inserted into columns with different data types. Long strings may be silently
truncated when inserted into columns with short maximum lengths. Also, there
are problems with precision when converting between NUMERIC and FLOAT
data types, and with data types when expressions involving values of different
types are computed and the results inserted. For example, the expression 1 +
32767 will be stored as 32768 when inserted into a SMALLINT column.
CREATE TABLE t2 (
key_col INTEGER NOT NULL DEFAULT AUTOINCREMENT,
col_2 VARCHAR ( 100 ) NOT NULL,
col_3 VARCHAR ( 100 ) NOT NULL,
col_4 VARCHAR ( 100 ) NOT NULL,