自动增加列 [英] auto increment the column

查看:146
本文介绍了自动增加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个表,现在我必须在不使用创建序列"的情况下将自动增量属性设置为创建的表字段"id".
注意:字段"id"不是主键
在此先感谢.

I have created a table and now i have to set the auto increment property to the created table field ''id'' without using ''create sequence''.
NOTE:the field ''id'' is not a primary key
Thanks in advance.

推荐答案

AFAIK在Oracle中没有自动增量列之类的概念.序列用于生成代理密钥.序列给定的值可以在任何地方使用,不仅可以在主键中使用.

您可以通过在表上创建插入触发器并使用触发器中的序列设置字段值来模仿自动增量列的行为.这样,客户端应用程序会自动生成"该列.
AFAIK in Oracle there''s no such concept as auto increment column. Sequences are used to generate surrogate keys. The value given by a sequence can be used anywhere, not only in primary keys.

You can mimic the behaviour of auto incerement columns by creating an insert trigger on your table and setting the field value using a sequence in the trigger. This way the client application ''thinks'' the column is autogenerated.


在Oracle中,您可以使用序列创建一个自动编号字段.序列是Oracle中用于生成数字序列的对象.当您需要创建一个唯一的数字作为主键时,这很有用.
参考链接:-
Oracle/PLSQL:序列(自动编号) [在Oracle中创建更好的自动增量列 [
In Oracle, you can create an autonumber field by using sequences. A sequence is an object in Oracle that is used to generate a number sequence. This can be useful when you need to create a unique number to act as a primary key.
Reference Link :-
Oracle/PLSQL: Sequences (Autonumber)[^]
Creating BETTER auto-increment columns in Oracle[^]


这篇关于自动增加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆