ORM Source Model Generates Incorrect DDL Code for Unique Constraint on Optional Columns (814724)
The information in this article applies to:
- Microsoft Visio for Enterprise Architects (2002)
SYMPTOMSWhen you use Microsoft Visio for
Enterprise Architects to generate the Data Definition Language (DDL) script
for an Object Role Modeling (ORM) Source Model, and you have a unique constraint defined on a nullable column, you
may receive the following warning message: Full
path of project file : warning P1710: 'Table Name.Column
Name' : Primary key/unique constraint column is declared as nullable. Table
can be created but you may not insert more than one null value into this column
because it violates the constraint imposed by the DBMS. In some databases, you cannot insert
more than one null value in the unique constraint column if you create the table
by using the generated DDL script. STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
WORKAROUNDTo work around this problem, you can use check constraints or
triggers that have customized code to enforce uniqueness for a nullable column,
instead of using unique constraints. SQL-92 Code Examples for Check ConstraintsCHECK (UNIQUE (SELECT DeptHeaded FROM Employee
WHERE DeptHeaded IS NOT NULL)) CHECK (NOT EXISTS (SELECT DeptHeaded FROM Employee
WHERE DeptHeaded IS NOT NULL
GROUP BY DeptHeaded
HAVING COUNT(*) > 1) )
SQL Server Example for TriggerCREATE TRIGGER Unique_DeptHeaded
ON Employee
AFTER INSERT, UPDATE
AS
IF EXISTS (SELECT DeptHeaded FROM Employee
WHERE DeptHeaded IS NOT NULL
GROUP BY DeptHeaded
HAVING count(*) > 1)
BEGIN
RAISERROR('Attempt was made to insert a duplicate DeptHeaded. The statement will be rolled back.',16,1)
ROLLBACK
END Note For the examples that appear in this article, assume that the tables do not have
any duplicate data existing. You can also use these examples when you create the
tables. REFERENCESFor more information about how to create ORM Source Models by using
Microsoft Visio for Enterprise Architects, visit the following Microsoft Web
site:
Modification Type: | Major | Last Reviewed: | 6/18/2003 |
---|
Keywords: | kbpending kbTSQL kbTrigger kberrmsg kbDesigner kbCodeGen kbbug KB814724 kbAudDeveloper |
---|
|