0

Could I change order in generated script for CHECK constraint on TABLE? I need to generate Check Constraint at the end (when tables and functions exists). Because I have a function F (Select COUNT (*) from table X), and I have a constraint on table Y with Check function

example:

Create function F
RETURNS int
QUERY....
RETURN SELECT COUNT (*) FROM TABLE X
END
GO

ALTER TABLE Y ADD Constraint ConstraintName dbo.Function F ()= 1

When I change order for procedures, the scripts fails for DROP FUNCTION (there is a reference in Y).

pascal
  • 3,287
  • 1
  • 17
  • 35

1 Answers1

0

You should create a Traceability Link of type DBCreateAfter, from table Y to function F, and from function F to table X.

This should fix the create, and the drop order.

pascal
  • 3,287
  • 1
  • 17
  • 35
  • Thank you for your advice - perhaps it would be route, but there are new feews problems.. In this table Y are many foreign keys :-) which also have some references to other tables.... Do I have to create Tracebilities to all (referenced) tables? There are in the script is DROP TABLE Y on the first place... but because of references to another tables the scripty does not work :-) On the second place in the script is Drop Function (after drop TABLE Y - that is correct). Thank you for your help. – user2408345 Dec 18 '17 at 14:38
  • I've just tried to create an Oracle model. By default, the Foreign Key was generated as `outside` (as `alter table add constraint foreign key...` rather than `create table (... foreign key...`). This allows for circular dependency. This `outside`option is under `Database > Generate Database > Options > Foreign key`, once you have references in your model. – pascal Dec 19 '17 at 07:15