sql - 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 .
解决方案
您可以执行以下操作:
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 不允许您将列放在列列表的开头。它总是被添加到最后。
推荐阅读
- elasticsearch - 在 C# 中并行调用 Elasticsearch
- angular - @Viewchild 不适用于角度
- angularjs - Angular 性能升级没有 $rootscope、$location 的提供者
- python - 使用 group by 来获取 n 个最小值但有重复项
- angular - 在 Angular 中使用 Highcharts (>= 8.0.1) 函数 stockChart() 时出错
- python - 如何将完整的代码存储在变量中
- c - C 中的 const 数据修改
- javascript - 为更新数据库反应更新对象值(数量)
- cakephp - Cakephp .json ext 给 Missing Method
- c# - 为什么我的应用程序可以在我的计算机上运行,但不能在其他计算机上运行