我想从类似于here的序列设置列的默认值,但也在序列前面添加一个值,以便表中保存的值看起来像{{1 }}。这可能吗?
答案 0 :(得分:3)
完全可能。
从您已关联的帖子更改示例:
create sequence mainseq as bigint start with 1 increment by 1;
create table mytable (
id varchar(20) not null constraint DF_mytblid default 'p' + CAST(next value for mainseq as varchar(10)),
code varchar(20) not null
)
测试:
INSERT INTO MyTable (Code) VALUES ('asdf'), ('cvnb')
SELECT *
FROM MyTable
结果:
id code
p1 asdf
p2 cvnb