[英]How to Update a column which is created by using cast - identity
Is there any way to update column which is created with cast 有什么方法可以更新使用演员表创建的列
CREATE TABLE test
(
num INT IDENTITY(1, 1),
Token AS 'TK_' + CAST(num VARCHAR(10)),
name VARCHAR(100)
)
INSERT INTO test VALUES ('data')
If I execute the above query, my result for token column will be "tk_1". 如果执行以上查询,则令牌列的结果将为“ tk_1”。
Is it possible to update/insert manually for that "token" column value? 是否可以为该“令牌”列值手动更新/插入?
Computed columns are read-only and IDENTITY
values cannot be updated. 计算列为只读,并且
IDENTITY
值无法更新。 With the computed column, all you can do is indirectly control the value during inserts using IDENTITY_INSERT
but that defeats the purpose of using IDENTITY
. 使用计算列,您所能做的就是在使用
IDENTITY_INSERT
过程中间接控制该值,但这违背了使用IDENTITY
的目的。
If you want to update the value after inserted, make it a regular varchar(13)
column and assign the initial value in an insert trigger. 如果要在插入后更新值,请使其成为常规的
varchar(13)
列,并在插入触发器中分配初始值。 That would allow you to update the value to something else after the initial insert. 这将允许您在初始插入后将值更新为其他值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.