E
Erland Sommarskog
Luc said:i solved this by adding a varchar field in table 'student' and promoting
it in combinaison with a unique identifier to primary key. In that
field, this value is inserted: CONVERT(varchar(20), GETDATE(), 113))
When two students try at the same time to subscribe, there must be at
least one second of difference between both students. I did this because
when putting the value getdate() in a DateTime field, two students will
normaly never have exactly the same milli-second.
Certainly an unorhtodox solution. You have add a varchar value which does
not really carry any information to the primary key? And when the student
signs up for the next project, you change that value?
Well, you still need the trigger to avoid that a project get overbooked.
There is one another approach though. When the project is created, also
create the slots for the students. When a student signs up, you update the
first free row. Check @@rowcount after the UPDATE, and if it's zero, there
were no free slots. There is no possibility for a double booking here.
--
Erland Sommarskog, SQL Server MVP, (e-mail address removed)
Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx