While creating a table a particular column / field can be made autoincrement as :
1 | CREATE TABLE students |
2 | ( |
3 | id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), |
4 | name VARCHAR(24) NOT NULL, |
5 | address VARCHAR(1024), |
6 | CONSTRAINT primary_key PRIMARY KEY (id) |
7 | ) ; |
The
value of an autoincrement column increments automatically with every
insert and doesnt need to be specified in the insert command. It is 1 +
the value of the same field in the previous row.
Now data can be inserted as :
1 | insert into students(name , address) values('Sanjay' , 'New Delhi'); |
Note
that the value for the id field (which is an autoincrement field) is
not specified. It fills automatically by taking the value of the
previous row and adding 1 to it.
******************* MYSQL *******************
CREATE TABLE tb_table (
table_seq INT(11) NOT NULL AUTO_INCREMENT COMMENT 'table 고유아이디',
database_seq INT(11) NOT NULL COMMENT 'database 고유아이디 (FK)',
table_name VARCHAR(100) NOT NULL COMMENT 'table 실제 이름',
table_owner_name VARCHAR(100) COMMENT 'table 소유자 이름',
table_type VARCHAR(10) COMMENT 'table 용도 : [table type] 코드 정의 참고',
enc_name VARCHAR(100) COMMENT '암호화된 table 이름',
description VARCHAR(1000) COMMENT 'table 설명',
PRIMARY KEY ( table_seq ),
UNIQUE KEY uk_table_name (database_seq, table_name, table_owner_name),
CONSTRAINT fk_table FOREIGN KEY ( database_seq ) REFERENCES tb_database ( database_seq ) ON DELETE CASCADE
) DEFAULT charset=utf8;
댓글 없음:
댓글 쓰기