如何保持数据库一致性 [英] How to maintain database consistency

查看:211
本文介绍了如何保持数据库一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库表,其中有一个教授列表,从我的网站用户可以搜索并选择一天的教授。

一旦学生选择了我不想要的教授那个教授要在其他用户的教授名单中,如果那个用户没有确认和这位教授一起去,那么他应该再次显示在列表中。

这是一个例子,我有四位教授P1,P2,P3和P4

所有用户都可以看到所有这些用户现在用户U1选择P2所以其他用户应该看到P1,P3和P4
另外,在下一页上如果用户U1没有确认,那么我必须将P2添加回列表。

如何在asp.net 4.0中实现这一点Sql server 2008

解决方案

您还没有说过您正在使用的数据库访问技术,所以我只是向您展示原始SQL。如果你正在使用像ADO.net,LinqtoSQL,Entity Framework,NHibernate等特定的东西,那么你真的应该在你的问题中提到这些东西,因为它经常会产生重大影响。



将一个bit \Booleanlocked字段添加到教授数据库中,当你找回教授时



 更新教授 SET 已锁定=  1   WHERE  ID =  123  

SELECT * 来自教授 WHERE ID = 123





然后当用户选择不接受该教授查看时



< pre lang =sql> 更新教授 SET 已锁定= 0 WHERE ID = 123





然后你更新显示可用教授列表的sql,以排除那些被锁定的教授



  SELECT  * 来自教授 WHERE 已锁定=  0  


I have a database table which has a list of professor, from my website users can search and select a professor for a day.
As soon as a student select a professor I don't want that professor to be in the list of professors for other users and if that user doesn't confirm to go with this professor then again he should be displayed in the list.
Here is an example, I have four professors P1, P2,P3 and P4
All users can see all of them
now a user U1 select P2 so all other users should see P1,P3 and P4
Also, on next page if user U1 doesn't confirm then I have to add that P2 back to the list.
How can I achieve this in asp.net 4.0 with Sql server 2008

解决方案

You haven't said what database access technology you're using so I'm just going to show you the raw SQL. If you are using something specific like ADO.net, LinqtoSQL, Entity Framework, NHibernate etc then you really should mention these things in your question as it often makes all the difference.

Add a bit\Boolean "locked" field to the Professor database and when you retrieve the professor

UPDATE Professor SET Locked = 1 WHERE ID = 123

SELECT * From Professor WHERE ID = 123



Then when the user chooses to not accept that professor to view

UPDATE Professor SET Locked = 0 WHERE ID = 123



You then update the sql that shows the list of available professors to exclude those that are locked

SELECT * From Professor WHERE Locked = 0


这篇关于如何保持数据库一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆