SQL Server身份对应问题 [英] SQL Server identity counterpart problem

查看:67
本文介绍了SQL Server身份对应问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL Server,并且想在其中使用身份约束

I'm using SQL Server and I want to use identity constraint in it

我知道如何以以下方式使用

I know how to use it in following manner

create table mytable
(
 c1 int primary key identity(1,1);
)

上面的代码工作正常,但是如果我希望标识列具有EMP001,EMP002,...而不是1,2 ......

the above code works fine but what if i want the identity column to have values as EMP001, EMP002,... instead of 1,2....

预先感谢, 上师

推荐答案

标识列只能是整数.如果您希望它看起来像"EMP001","EMP002"等,那么这仅仅是一个显示问题,而不是存储问题(也就是说,您无需存储"EMP001","EMP002"等等,只需通过常规标识列将其存储为1、2、3,并在应用程序中将其 display 分别显示为"EMP001","EMP002"等)

Identity columns can only be integers. If you want it to "look like" EMP001, EMP002, etc then that's simply a display issue and not a storage one (that is, you don't need to store "EMP001", "EMP002" etc, just store it as 1, 2, 3 via a normal identity column and display it in your application as "EMP001", "EMP002", etc)

这篇关于SQL Server身份对应问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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