server中自动生成员工ID的问题

server中自动生成员工ID的问题

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

问题描述

嗨朋友

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

这里是我创建表的代码

创建表employee(ID int identity, EmployeeID as(('Emp')+ replicate('0',8-Len(ID))+ Cast(ID as Varchar))持久化主键,FirstName Varchar(50)非null,LastName Varchar(50)非null) 



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

这里是警告:

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

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



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

谢谢

解决方案



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)


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

解决方案



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

08-20 19:49