SQL自动生成的varchar id基于条件 [英] SQL auto generated varchar id based on condition
本文介绍了SQL自动生成的varchar id基于条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi,
I want to gernerate a unique varcahr id bsaed on city address, ID should be like this PKRKHRAL01234 (where KHR is code for city name and it will change when city name changes) how can i achieve this?
推荐答案
请参阅: http:// www。 sqlteam.com/article/custom-auto-generated-sequences-with-sql-server [ ^ ]
问候..
See this : http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server[^]
Regards..
在t上使用计算列应该把主钥匙和城市放在一起,每当有人改变城市,这个代码就会改变
PKR =静态
KHR =城市列
AL =静态
01234 =主键
语法创建计算列
ALTER TABLE [YourTable]添加AutoCityCode AS('PKR'+ City +'AL'+ ID);
use a calculated column on the table which should put togather the Primary Key and the city, and whenever someone changes the city this code will change along
PKR = Static
KHR = City Column
AL = Static
01234 = Primary Key
syntax to create calculated column
ALTER TABLE [YourTable] ADD AutoCityCode AS ('PKR' + City + 'AL' + ID);
这篇关于SQL自动生成的varchar id基于条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文