DB2 Add hidden Identity columns
An identity column contains a unique numeric value for each row in the table. DB2® can automatically generate sequential numeric values for this column as rows are inserted into the table. Thus, identity columns are ideal for primary key values, such as employee numbers or product numbers.
You can define an identity column as either GENERATED BY DEFAULT or GENERATED ALWAYS:
- If you define the column as GENERATED BY DEFAULT, you can insert a value, and DB2 provides a default value if you do not supply one.
- If you define the column as GENERATED ALWAYS, DB2 always generates a value for the column, and you cannot insert data into that column. If you want the values to be unique, you must define the identity column with GENERATED ALWAYS and NO CYCLE and define a unique index on that column.
Suppose that table T1 is defined with GENERATED ALWAYS and CYCLE:
CREATE TABLE T1
(CHARCOL1 CHAR(1),
IDENTCOL1 SMALLINT GENERATED ALWAYS AS IDENTITY
(START WITH -1,
INCREMENT BY 1,
CYCLE,
MINVALUE -3,
MAXVALUE 3));
INSERT INTO T1 (CHARCOL1) VALUES ('A');
CHARCOL1 IDENTCOL1
======== =========
A -1
A 0
A 1
A 2
A 3
A -3
A -2
A -1
The following example adds a column to the table DSN8910.DEPT, which contains a location code for the department. The column name is LOCATION_CODE, and its data type is CHAR (4).
ALTER TABLE DSN8910.DEPT
ADD LOCATION_CODE CHAR (4);
Add hidden column 需要加关键字,参考这里:
http://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/com.ibm.db2z10.doc.sqlref/src/tpc/db2z_sql_altertable.dita?lang=en
DB2 Add hidden Identity columns的更多相关文章
- Oracle列自增实现(2)-Identity Columns in Oracle Database 12c Release 1 (12.1)
Oracle列自增-Identity Columns in Oracle Database 12c Release 1 (12.1) 在ORACLE 12C以前的版本中,如果要实现列自增长,需要通过序 ...
- Oracle 12C -- Identity Columns(标识列)
Identity Columns很适合数据库中需要"surrogate keys"的场景.依赖sequence产生器,每行的标识列会被赋予一个自增或自减的值.缺省,标识列在创建的时 ...
- DevExpress Add ASPxGridView template columns at runtime
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Import Namespace ...
- Oracle 12c的自增列Identity Columns
在Oracle的12c版本中,Oracle实现了类似MySQL中的auto_increment的自增列,下面我们看一起Oracle是怎么实现的. Oracle Database 12c Enterpr ...
- asp.net—自定义轻量级ORM
大型项目中ORM的使用已经是相当的频繁.目前.NET(C#)中比较流行的ORM框架也有很多,比如SqlSugar,Dapper,Entity Framework(EF)等. 相信很多有2年以上工作经验 ...
- 连表查询都用Left Join吧 以Windows服务方式运行.NET Core程序 HTTP和HTTPS的区别 ASP.NET SignalR介绍 asp.net—WebApi跨域 asp.net—自定义轻量级ORM C#之23中设计模式
连表查询都用Left Join吧 最近看同事的代码,SQL连表查询的时候很多时候用的是Inner Join,而我觉得对我们的业务而言,99.9%都应该使用Left Join(还有0.1%我不知道在 ...
- DB2 for z: system catalog tables
http://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/com.ibm.db2z10.doc.sqlref/src/tpc/db2z_cata ...
- Microsoft.AspNet.Identity.EntityFramework/IdentityDbContext.cs
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; ...
- DB2 移动数据总结一
数据移动参考的连接 IMPORT http://www-01.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.admin.cm ...
随机推荐
- Effective Java 读书笔记之八 异常
一.只针对异常的情况才使用异常 1.类具有状态相关的方法时,可采用状态测试方法和可识别的返回值两个策略. 二.对可恢复的情况使用受检异常,对编程错误使用运行时异常 1.期望调用者能够适当恢复的情况,应 ...
- Android开发学习笔记--给一个按钮定义事件
学习Android的第一天,了解了各种布局,然后自己动手画出了一个按钮,然后给按钮定义了一个事件是弹出一条消息显示“我成功了!”字样,具体过程如下: 1.修改布局文件activity_main.xml ...
- 揭露QPS增高后的秘密
导读 很多人在实际的开发中害怕系统的QPS增高,因为觉得QPS太高会导致系统挂掉;基于这种心理会想着尽量的降低系统的请求量,甚至有人会将很多处理放置到服务中来处理,这样外部发一起请求,服务就把所有的业 ...
- CSS 继承深度解析
FROM ME: 之前在研究前端性能优化的时候,就有学习关于CSS中“善用CSS中的继承”. 原文:CSS Inheritance, The Cascade And Global Scope: You ...
- (备忘)android模拟器摄像头模拟
Camera分Front Camera和Back Camera 通常我们模拟后摄像头就可以了 三个选项 none:表示没有摄像头,打开摄像应用会崩溃 emulated:系统模拟一个动态的画面--在黑白 ...
- 项目:BluetoothChat
代码在github: https://github.com/Viyu/BluetoothChat 蓝牙聊天核心是Android Demo里的,我加上了类似微信的界面. 我觉得这个应用要是能推广的话,有 ...
- net-snmp子代理(SubAgent)编写详述
net-snmp子代理(SubAgent)编写 net-snmp子代理(SubAgent)编写 Netsnmp_Node_Handler MIB/OID定义 1.头文件test.h的编写 2.test ...
- 浏览器JS脚本
javascript: void((function() { alert("zeze"); })()) javascript:
- linux 终端报错 Out of memory: Kill process[PID] [process name] score问题分析
从Out of memory来看是内存超出了,后面的 Kill process[PID] [process name] score好像和进程有关了,下面我们就一起来看看linux 终端报错 Out o ...
- Android 自动化测试 常用的命令----随时更新
常用命令分为三类,如下: 1. android android sdk : 打开SDK管理器. android avd : 打开虚拟设备管理器. android --help : 查看帮助信息. 2. ...