Friday, March 9, 2012

Req help with data types/domains

Hi,

I have a data type called ModelElement_t, the type contains 2 attributes: name & visibility. name can be represented as a string, only visibility is to be represented as an adt visibilityKind

CREATE TYPE ModelElement_t AS (name varchar, visibility visibilityKind)

CREATE TYPE visibilityKind_t AS (??

visibilitykind can be of 5 possible settings:vk_public, vk_protected, vk_private, vk_package, & vk_notapplicable. the default setting is vk_public.

could anyone give me any suggestions how to represent this, in conformance with the relational model? Im wondering if an array may be appropriate (only im not sure how to do this) or use constraint settings. I'd be appreciative if someone could display the SQL code. Any suggestions welcome.

Thanks in advance,

FAC51 :)I believe the SQL approach would be like:
create domain visibilityKind_t varchar2(16)
constraint visibilityKind_chk check value in ('vk_public', 'vk_protected', 'vk_private', 'vk_package', 'vk_notapplicable');
I am less clear about the OO "create type" approach. This tends to vary from vendor to vendor. The way it works in Oracle, there can be no constraint on the TYPE itself, only on columns of the TYPE - i.e.:

CREATE TYPE visibilityKind_t AS OBJECT (kind VARCHAR2(16));

CREATE TYPE ModelElement_t AS OBJECT (name varchar, visibility visibilityKind);

CREATE TABLE x (id INT, ModelElement ModelElement_t,
CONSTRAINT visibilityKind_chk CHECK ModelElement.kind IN ('vk_public', 'vk_protected', 'vk_private', 'vk_package', 'vk_notapplicable')
);
... which is poor, in my opinion.|||hi andrew, thanks for your reply, it was quite a tricky one i put out, i have a much better understanding now, thanks!

I believe the SQL approach would be like:
create domain visibilityKind_t varchar2(16)
constraint visibilityKind_chk check value in ('vk_public', 'vk_protected', 'vk_private', 'vk_package', 'vk_notapplicable');
I am less clear about the OO "create type" approach. This tends to vary from vendor to vendor. The way it works in Oracle, there can be no constraint on the TYPE itself, only on columns of the TYPE - i.e.:

CREATE TYPE visibilityKind_t AS OBJECT (kind VARCHAR2(16));

CREATE TYPE ModelElement_t AS OBJECT (name varchar, visibility visibilityKind);

CREATE TABLE x (id INT, ModelElement ModelElement_t,
CONSTRAINT visibilityKind_chk CHECK ModelElement.kind IN ('vk_public', 'vk_protected', 'vk_private', 'vk_package', 'vk_notapplicable')
);
... which is poor, in my opinion.

No comments:

Post a Comment