如何在数据库中强制执行数据完整性规则? [英] How do I enforce data integrity rules in my database?
问题描述
我正在设计这个类和抽象(MustInherit)类的集合...
I'm designing this collection of classes and abstract (MustInherit) classes…
class diagram http://img396.imageshack.us/img396/1711/nodeclassinheritanceej0.gif
这是数据库表,我要存储所有这些...
This is the database table where I'm going to store all this…
数据库表http://img179.imageshack.us/img179/3237/nodetablenorootln3.gif
As
但是,实际上,这取决于存储在那里的类:LinkNode,HtmlPageNode(Allow Nulls)。 ,或CodePageNode。
But really, that depends on the class stored there: LinkNode, HtmlPageNode, or CodePageNode.
规则可能如下所示:
rules table http://img127.imageshack.us/img127/74/datarulesha0.gif
如何在我的数据库中实施此类数据完整性规则?
How do I enforce such data integrity rules within my database?
关于这个单表设计...
UPDATE: Regarding this single-table design...
我仍然试图在最终的架构上归零。
I'm still trying to zero in on a final architecture.
我最初开始用许多小表,几乎零nullalbe字段。
这是我导航的最好的数据库模式?
I initially started with many small tables with almost zero nullalbe fields.
Which is the best database schema for my navigation?
我学习了LINQ to SQL IsDiscriminator属性。 >
最好的方法来处理SQL中的一对一关系?
And I learned about the LINQ to SQL IsDiscriminator property.
What’s the best way to handle one-to-one relationships in SQL?
但是我了解到LINQ to SQL只支持单表继承。
LINQ to SQL IsDiscriminator列是否可以继承?
But then I learned that LINQ to SQL only supports single table inheritance.
Can a LINQ to SQL IsDiscriminator column NOT inherit?
现在我试图用一组类和抽象类来处理它。
请帮助我的.NET抽象类。
Now I'm trying to handle it with a collection of classes and abstract classes.
Please help me with my .NET abstract classes.
推荐答案
对表使用CHECK约束。这些允许您使用任何布尔逻辑(包括表中的其他值)来允许/拒绝数据。
Use CHECK constraints on the table. These allow you to use any kind of boolean logic (including on other values in the table) to allow/reject the data.
从在线图书网站:
您可以使用
创建CHECK约束任何逻辑(布尔)表达式,
基于
逻辑运算符返回TRUE或FALSE。对于先前的
示例,逻辑表达式是:
salary> = 15000 AND salary <= 100000。
You can create a CHECK constraint with any logical (Boolean) expression that returns TRUE or FALSE based on the logical operators. For the previous example, the logical expression is: salary >= 15000 AND salary <= 100000.
这篇关于如何在数据库中强制执行数据完整性规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!