如何在SQL Server自动递增中有两列? [英] How can I have two columns in SQL Server auto increment?

查看:69
本文介绍了如何在SQL Server自动递增中有两列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在添加新字段时自动增加一个SQL Server数据库表中的两列.但是,Managment Studio不允许我将两列设置为IDENTITY.还有其他方法吗?

I have two columns in a table of a SQL server DB that I would like to autoincrement when new fields are added. However, Managment Studio wont allow me to set two columns to IDENTITY. Is there some other way to do this?

推荐答案

您可以将第二个字段设为基于第一个字段的计算字段.

You could make the second field a calculated field based on the first.

或者进行INSERT触发器,而不是以编程方式为第二个生成值.

Or make an INSERT trigger than programatically generates the value for the second.

这篇关于如何在SQL Server自动递增中有两列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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