在slq服务器中自动生成员工ID的问题 [英] Problem with autogenerating employee id in slq server

查看:110
本文介绍了在slq服务器中自动生成员工ID的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友

i我在sql server中自动生成一个员工ID,但我并没有使用身份在1,2,3中生成它....序列我希望它在一个格式如此Emp00001所以决定操纵我的代码

这里是我创建表的代码

Hi friends
i am auto generating an employee id in sql server, but i didnt just wana use identity to generate it in the 1,2,3.... Sequence i want it in a format like this Emp00001 so decided to manipulate my code
here is my code to create the table

Create table employee ( ID int identity, EmployeeID as (('Emp') + replicate ('0', 8 - Len(ID)) + Cast (ID as Varchar)) persisted Primary Key, FirstName Varchar(50) not null, LastName Varchar(50) not null)



但是这个代码的问题在于创建表后,sql server弹出两个警告让我真的很担心

这里是警告:

警告!最大密钥长度为900字节。索引'PK_Employee_1A89E4E1'的最大长度为800字节。对于某些较大值的组合,插入/更新操作将失败。

警告:行的最大长度超过允许的8060字节限制。对于某些大值的组合,插入/更新操作将失败。



是我使用的代码,或者不是一个好的做法请我需要sugestions

谢谢


but the problem am having with this code is that after creating the table, sql server pops up two warnings that got me realy worried
here are the warnings:
Warning! The maximum key length is 900 bytes. The index 'PK_Employee_1A89E4E1' has maximum length of 800 bytes. For some combination of large values, the insert/update operation will fail.
Warning: The maximum length of the row exceeds the permissible limit of 8060 bytes. For some combination of large values, the insert/update operation will fail.

is the code i used good, or is not a good practice please i need sugestions
thanks

推荐答案

请参考此链接:使用varchar作为主键值是否可以? [ ^ ]



就个人而言,我没有使用varchar字段作为主键。在我看来,这是一个坏主意;(
Please, refer this link: Using varchar for primary key value is ok?[^]

Personally i'm not using varchar field as a primary key. In my opinion it's a bad idea ;(


这篇关于在slq服务器中自动生成员工ID的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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