我有一张如下表:
StudentName, StudentNo, SchoolCode etc.,
----------- ---------- ----------
插入数据时,我必须根据SchoolCode
生成序列号。
对于Eg:SchoolCode:1序列号:1,2,3,...和SchoolCode:2再次它应该从1,2,3开始..
怎么做?
答案 0 :(得分:0)
您可以在school code
ALTER TABLE dbo.YourTable
ADD SCHOOL_CODE INT IDENTITY(1,1)
如果你想像这样生成'AA-01','AA-02'
那样的话:
CREATE TABLE dbo.Student
(
StudentId int NOT NULL PRIMARY KEY,
School_Code AS 'AA-' + CAST(StudentId as varchar(16))
)