如何将一个列的默认值设置为随机值,或当前时间戳的值
目的:为该列填充唯一值
百度,GOOGLE都搜索过了,没有找到,是太简单了,没有人愿意写出来?
谁有DB2的函数参考手册什么的,能不能发给我份,谢谢了
MSN E-Mail:fhp_a@hotmail.com
------解决方案--------------------------------------------------------
如何将一个列的默认值设置为随机值,或当前时间戳的值
目的:为该列填充唯一值
唯一值怎么能用随机值??会有重复的。
------解决方案--------------------------------------------------------
CREATE TABLE DB2INST1.CCC (
Code VARCHAR(25),
TTT INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1 ) NOT NULL
)
其实这样就可以满足你的要求吧 ?
默认值要么是变量、系统时间、用户等几个很少的函数。。。
见:IBM help ..
default-values
Specific types of default values that can be specified are as follows.
constant
Specifies the constant as the default value for the column. The specified constant must:
represent a value that could be assigned to the column in accordance with the rules of assignment as described in Chapter 3
not be a floating-point constant unless the column is defined with a floating-point data type
not have non-zero digits beyond the scale of the column data type if the constant is a decimal constant (for example, 1.234 cannot be the default for a DECIMAL(5,2) column)
be expressed with no more than 254 characters including the quote characters, any introducer character such as the X for a hexadecimal constant, and characters from the fully qualified function name and parentheses when the constant is the argument of a cast-function.
datetime-special-register
Specifies the value of the datetime special register (CURRENT DATE, CURRENT TIME, or CURRENT TIMESTAMP) at the time of INSERT, UPDATE, or LOAD as the default for the column. The data type of the column must be the data type that corresponds to the special register specified (for example, data type must be DATE when CURRENT DATE is specified).
user-special-register
Specifies the value of the user special register (CURRENT USER, SESSION_USER, SYSTEM_USER) at the time of INSERT, UPDATE, or LOAD as the default for the column. The data type of the column must be a character string with a length not less than the length attribute of a user special register. Note that USER can be specified in place of SESSION_USER and CURRENT_USER can be specified in place of CURRENT USER.
------解决方案--------------------------------------------------------
http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/admin/r0000927.htm
可以通过这里来查 。。。
里面非常详尽。
------解决方案--------------------------------------------------------
设置为自增列不就行了吗