MS SQL : Auto Generated Char+Number ID

Bagaimana membuat table column menjana ID seperti ABC001, ABC002, … dan seterusnya.

Create Table Foo(ID int identity, AlphaID As 'ABC' + Right('00' + Cast(ID As varchar(3)), 6) Persisted Primary Key, OtherData varchar(20));

Jika anda menggunakan Microsoft SQL Server Management Studio, anda boleh menambah code dibawah kedalam fill ‘Computed Column Specfication’ seperti contoh gambar di bawah.

'ABC' + Right('00' + Cast(ID As varchar(3)), 6)

formula

You may also like...

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.