首页 > 解决方案 > How to add unique identifier column in table?

问题描述

I have a table which does not have any unique identifier . I want to add unique column to table , how can I achieve this?

My table looks like this:

name age     gender      marital_status
SAM          M           Single
BOB          M           Married
JEN          F           Single
BOB          M           Married

I want my table to be like this:

id      name age     gender      marital_status
1        SAM          M           Single
2        BOB          M           Married
3        JEN          F           Single
4        BOB          M           Married

The reason I want to have unique identifier is because some of the records are duplicates of each other and I want to remove the duplicates .

标签: sqloracle

解决方案


您可以执行以下操作:

alter table t add id int;

create sequence t_seq;

update t set id = t_seq.nextval;

alter table t modify id primary key;

不幸的是,我认为 Oracle 不允许您将列放在列列表的开头。它总是被添加到最后。


推荐阅读