Reputation: 1
I have been developing one application to register the student's details for admission. In SQL Server, I have to save the records and generate one reference number. That registration should be unique.
At the present, I am taking max number from the table and insert into the table. Duplicate records inserted in milliseconds. How to avoid duplicate records in the reference number column? In my application, 1000 concurrent users register at the same time.
Ex. IRCTC Ticket booking. They are generating PNR without duplicate.
Upvotes: 0
Views: 24
Reputation: 522301
There is no reason why a regular auto increment primary key column should not suffice here:
CREATE TABLE students (
id INT NOT NULL IDENTITY PRIMARY KEY,
...
)
SQL Server would never generate a duplicate value for the above id
column. If, for some reason, this would not meet your expectations, then you could consider using a UUID for each student record, using the NEWID()
function.
Upvotes: 1