将自定义生成的值插入表中 [英] Insert Custom generated value into a table

查看:84
本文介绍了将自定义生成的值插入表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在像S001,S002之类的SQL表中插入一个自定义生成的值。我已经创建了一个表,并且我有像userid这样的列。每当插入记录时我如何自动插入自定义值。

解决方案

有两个选项



1.使用触发器生成值。 使用触发器 [ ^ ]

2.如果你正在使用它作为一个不同的字段然后你可以计算是否使用标识字段。使用替代列 [ ^ ]

触发器将是此的最佳解决方案


简单而好的解决方案是DEFAULT。



1.创建一个返回S001,S002等的函数。

2.在表格设计中将此函数设置为Default。



当您插入其他值时,它将自动填充。



您可以从中找到几乎相同的问题以下链接。请看下面我的评论。

我需要插入基于year_num的值



问候,

Vijay


I want to insert a custom generated value in a SQL table like S001,S002 like this.I have already created a table and i have column like userid in it.How can i auto insert the custom value whenever a record is inserted.

解决方案

There are two options

1. Use trigger to generate the value. Using trigger[^]
2. If you are using this as a different field then you can compute if using identity field.Using alternative column[^]


Trigger will be best solution for this


Simple and good solution is DEFAULT.

1. Create a function which will return S001,S002 ect.
2. Set this function as Default in table design.

When you insert other values it will be fill automatically.

Almost same problem you can find from below link. Please take a look my comment below.
I need to insert a value based on year_num

Regards,
Vijay


这篇关于将自定义生成的值插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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