Skip to Content
author's profile photo Former Member
Former Member

How to add the same business rule constraint to multiple tables

I've created a business rule that is defined as a constraint to restrict the start date from being after the end date. I'd like to apply the same rule to several tables in the db that have these same two column names. The problem is when I run the generated sql created by PowerDesigner I get an error that the constraint already exists. The generated sql is trying to create the constraint for every table. It works for the first table but every subsequent table gets the error.

Here's the sql being generated...


create table a (

id uniqueidentifier not null default new sequentialid(),

start_dt datetime null,

end_dt datetime null,

[some more columns],

constraint Start_End_Date_Rule check (start_dt is null or end_dt is null or start_dt <= end_dt)

)

go

What am I doing wrong?

Thanks,

Mark

PD 16.5

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 03, 2014 at 03:01 PM

    I figured it out. I needed to change the business rule type from "constraint" to "validation". That change creates the following sql...

    create rule Start_End_Date_Rule as

    start_dt is null or end_dt is null or start_dt <= end_dt

    go

    Then the sql created generates a unique name for each table constraint using the constraint name rule that I've defined...

    constraint ck_rule_loan_opt check (start_dt is null or end_dt is null or start_dt <= end_dt)

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.