Versions available for this page: CUBRID 8.3.0 | CUBRID 8.3.1 | CUBRID 8.4.0 | CUBRID 8.4.1 | CUBRID 8.4.3 | CUBRID 9.0.0 |
A column is a set of data values of a particular simple type, one for each row of the table.
<column_definition>::=
column_name column_type [[ <default_or_shared> ] | [ <column_constraint> ]]...
<default_or_shared>::=
{SHARED <value_specification> | DEFAULT <value_specification> } |
AUTO_INCREMENT [(seed, increment)]
<column_constraint>::=
NOT NULL | UNIQUE | PRIMARY KEY | FOREIGN KEY <referential definition>
How to create a column name, see Identifier.
You can alter created column name by using RENAME COLUMN clause of the ALTER TABLE.
The following is an example of creating the manager2 table that has the following two columns: full_name and age.
CREATE TABLE manager2 (full_name VARCHAR(40), age INT );
SHARED and DEFAULT are attributes related to the initial value of the column. You can change the value of SHARED and DEFAULT in the ALTER TABLE statement.
CREATE TABLE colval_tbl
( id INT, name VARCHAR SHARED 'AAA', phone VARCHAR DEFAULT '000-0000');
INSERT INTO colval_tbl(id) VALUES (1),(2);
SELECT * FROM colval_tbl;
;xr
=== <Result of SELECT Command in Line 3> ===
id name phone
=========================================================
1 'AAA' '000-0000'
2 'AAA' '000-0000'
--updating column values on every row
INSERT INTO colval_tbl(id, name) VALUES (3,'BBB');
INSERT INTO colval_tbl(id) VALUES (4),(5);
SELECT * FROM colval_tbl;
;xr
=== <Result of SELECT Command in Line 3> ===
id name phone
=========================================================
1 'BBB' '000-0000'
2 'BBB' '000-0000'
3 'BBB' '000-0000'
4 'BBB' '000-0000'
5 'BBB' '000-0000'
5 rows selected.
--changing DEFAULT value in the ALTER TABLE statement
ALTER TABLE colval_tbl CHANGE phone DEFAULT '111-1111'
INSERT INTO colval_tbl(id) VALUES (6);
SELECT * FROM colval_tbl;
;xr
=== <Result of SELECT Command in Line 1> ===
id name phone
=========================================================
1 'BBB' '000-0000'
2 'BBB' '000-0000'
3 'BBB' '000-0000'
4 'BBB' '000-0000'
5 'BBB' '000-0000'
6 'BBB' '111-1111'
6 rows selected.
You can define the AUTO_INCREMENT attribute for the column to automatically give serial numbers to column values. This can be defined only for SMALLINT, INTEGER, BIGINT(p,0), and NUMERIC(p,0) domains.
DEFAULT, SHARED and AUTO_INCREMENT cannot be defined for the same column. Make sure the value entered directly by the user and the value entered by the auto increment attribute do not conflict with each other.
AUTO_INCREMENT [(seed, increment)]
--AUTO_INCREMENT works only when no value is inserted on compat_mode=cubrid
CREATE TABLE auto_tbl(id INT AUTO_INCREMENT, name VARCHAR);
INSERT INTO auto_tbl VALUES(NULL, 'AAA'),(NULL, 'BBB'),(NULL, 'CCC');
INSERT INTO auto_tbl(name) VALUES ('DDD'),('EEE');
SELECT * FROM auto_tbl;
;xr
=== <Result of SELECT Command in Line 4> ===
id name
===================================
1 'AAA'
2 'BBB'
3 'CCC'
4 'DDD'
5 'EEE'
5 rows selected.