Dynamics AX 2012 唯一索引允许空值
Dynamics AX 2012 Unique Index Allow Nulls
在 ANSI SQL 中,您可以使用忽略“”值的 WHERE 子句创建唯一索引。
有没有办法在 Dynamics AX 中执行此操作?
向 table 添加唯一索引,只关心索引列包含数据的行?
我认为这是不可能的,因为 Dynamics AX 不允许空值:
Microsoft Dynamics AX does not support the concept of null values that is available in many other Database Management Systems (DBMS). A field in Microsoft Dynamics AX always has a type and a value.
- Null Values for Data Types [AX 2012], MSDN
更新
我认为不可能在 Dynamics AX 中设置仅适用于某些值而忽略其他值的 "selective" 索引。为此,您必须直接在 SQL 数据库中设置索引。当然数据字典同步会删除这样的索引。您可能可以编写一个 sql 过程来创建索引并自定义执行同步的代码以在每次同步后调用该过程。不过,我建议不要使用这种解决方案,因为它容易出错并且会绕过数据字典同步,而数据字典同步是 Dynamics AX 的核心机制之一。
另一种方法是将带有 '' 值的字段分隔到单独的 table 中,并且仅在该字段具有实际值时才在该 table 中创建记录。然后将新的 table 与现有的 table.
进行外部连接
另一种方法可能是不使用索引,而是编写一个数据验证程序来检查字段中的非空值是否已经存在。
在 ANSI SQL 中,您可以使用忽略“”值的 WHERE 子句创建唯一索引。
有没有办法在 Dynamics AX 中执行此操作?
向 table 添加唯一索引,只关心索引列包含数据的行?
我认为这是不可能的,因为 Dynamics AX 不允许空值:
Microsoft Dynamics AX does not support the concept of null values that is available in many other Database Management Systems (DBMS). A field in Microsoft Dynamics AX always has a type and a value.
- Null Values for Data Types [AX 2012], MSDN
更新
我认为不可能在 Dynamics AX 中设置仅适用于某些值而忽略其他值的 "selective" 索引。为此,您必须直接在 SQL 数据库中设置索引。当然数据字典同步会删除这样的索引。您可能可以编写一个 sql 过程来创建索引并自定义执行同步的代码以在每次同步后调用该过程。不过,我建议不要使用这种解决方案,因为它容易出错并且会绕过数据字典同步,而数据字典同步是 Dynamics AX 的核心机制之一。
另一种方法是将带有 '' 值的字段分隔到单独的 table 中,并且仅在该字段具有实际值时才在该 table 中创建记录。然后将新的 table 与现有的 table.
进行外部连接另一种方法可能是不使用索引,而是编写一个数据验证程序来检查字段中的非空值是否已经存在。