【已解决】doris 使用自增主键如何对已存在的表添加主键

Viewed 117
CREATE table if not EXISTS test_auto_inc3(   
	uid BIGINT not NULL,
	`stu_name` string NOT NULL,
	`score` BIGINT NOT NULL
)ENGINE=OLAP
DUPLICATE KEY(`uid`)
DISTRIBUTED BY HASH(`uid`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 3"
);
INSERT into test_auto_inc3(uid,stu_name,score) values(1,"Bob", 10), (2,"Alice", 20), (3,"Jack", 30);
SELECT * FROM test_auto_inc3

alter table example_db.test_auto_inc3 ADD COLUMN id bigint AUTO_INCREMENT(1)  AFTER uid;
SELECT * FROM test_auto_inc3

INSERT into test_auto_inc3(uid,stu_name,score) values(4,"Bob", 10), (5,"Alice", 20), (6,"Jack", 30);
SELECT * FROM test_auto_inc3 ORDER BY uid

image.png

2 Answers

【问题状态】已解决
【问题处理】给已有表中加自增主键,原有数据的自增主键字段是不会有数据的

为啥自增主键是从0开始,而不是默认值1开始