August 31, 2014 at 2:43 am
Hi all,
In an interview i was asked this question, some body please help me.
"In a supermarket there is a bill entry system, so if all users are clicking new bill at same time, they all will be getting the same bill number, so while saving this to database, there will be conflict, how can this be solved using sql server"
Please help.
August 31, 2014 at 3:33 am
Not enough information.
What system provides the billing number in the first place?
If an app would request a billing number from SQL Server, it could be guaranteed that there'll never be two identical numbers returned by SQL Server.
But if the app picks the number by itself and the duplicate is detected during insert (unique constraint violation), the issue cannot be "solved" using SQL Server since all that can be done from SQL Server side is to report the violation. The app would have to deal with the error message and provide a logic to resolve the conflict.
August 31, 2014 at 3:37 am
only this much was asked in the interview, i gave her one logic in C#, but she was not satisfied by it,
she said there is a way to do this in SQL server, and its very simple, i couldn't find any information online, is it she talking about Transaction ??? im not sure ...
or is der any logic used for generating bill number in sql ?
August 31, 2014 at 3:50 am
Like I wrote before: not enough information.
There are several ways to provide a unique billing number using SQL Server.
Either a table with pre-generated numbers where a used number is marked as "used".
Or the number is generated "on the fly" and inserted into a separate table.
For both scenarios, the column holding the billing number would have a unique constraint and for the update or insert an exclusive table lock is required to prevent other processes from reading/manipulating the data (or a "retry-process" to get a new number if the update or insert fails with constraint violation).
August 31, 2014 at 4:06 am
i hope may b she was expecting dis ....:)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply