我需要使用 ASP.NET 生成如下公式的学号。
因此,每次将学生添加到数据库时,它都应该自动生成一个学生 ID。
注意(将新学生添加到数据库时,我需要知道已添加到数据库中的最后一个学生 ID,以便它可以遵循正确的公式)。
RS 1011000
RS 1011001
RS 1011002
RS 1011003
RS 1011004
创建一个 id 列作为 bigint identity(10000000, 1) 和一个计算列,该列在该列前面加上“RS”。
所以你会得到类似的东西
创建表示例 (studentId bigint not null identity(10000000, 1), RsNumber as 'RS' + CAST(studentId as varchar(15)))
http://www.kodyaz.com/articles/sql-server-computed-column-calculated-column-sample.aspx