如何在列上添加 HIDDEN 属性? [英] How to add HIDDEN property on column?

查看:33
本文介绍了如何在列上添加 HIDDEN 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建临时表时,我们需要定义开始和结束日期时间列可以是 hidden - 在 SELECT *INSERT without columns 中不可见.我想再添加一列,其中将包含有关已提交更改的用户的信息.

When temporal table is created, we need to defined start and end date time columns which can be hidden - not visible in SELECT * or INSERT without columns. I want to add one more column, which will contain information about the user who has commit the change.

问题是,我收到以下错误:

The issue is, I am getting the following error:

Msg 13735, Level 16, State 1, Line 10
Cannot alter HIDDEN attribute on column 'UserID' in table 'GK' because this column is not a generated always column.

代码如下:

DROP TABLE IF EXISTS GK;

CREATE TABLE GK
(
    [ID] INT
   ,[UserID] BIGINT DEFAULT (CONVERT(BIGINT, SESSION_CONTEXT(N'user_id')))  
)

ALTER TABLE GK
ALTER COLUMN [UserID] ADD HIDDEN;

为什么不允许我在此类列上添加此属性?

Why I am not allowed to add this attribute on such column?

推荐答案

为此你需要像下面这样使用

FOR this you need to use like below

[ GENERATED ALWAYS AS ROW { START | END } [ HIDDEN ] ] 

GENERATED ALWAYS AS ROW START/END 是强制性的.和

GENERATED ALWAYS AS ROW START/END is compulsory. and

另请注意,系统版本表不能有多个GENERATED ALWAYS AS ROW END"列

Also note that System-versioned table cannot have more than one 'GENERATED ALWAYS AS ROW END' column

另请注意,系统版本表不能有多个GENERATED ALWAYS AS ROW START"列

Also note that System-versioned table cannot have more than one 'GENERATED ALWAYS AS ROW START' column

因此,如果您已经在使用 2 个日期列,那么这是不可能的.我认为我们可以使用带有默认值的普通列.

So if you are already using 2 dates column then it will not be possible. I think we can just use a normal column with default value.

请参考 Microsoft - https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql

Refer more from Microsoft - https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql

这篇关于如何在列上添加 HIDDEN 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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