Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

Superclass Conflict

Adding a super class

The INHERIT clause of the ALTER CLASS statement is optional, but must be used when a conflict occurs due to class changes. You can specify more than one resolution after the INHERIT clause.

superclass_name specifies the name of the super class that has the new attribute or method to inherit when a conflict occurs. attr_mthd_name specifies the name of the attribute or method to inherit. You can use the AS clause when you need to change the name of the attribute or method to inherit.

The following example shows how to create the soccer_stadium class by inheriting the event and stadium classes in the olympic database of demodb. Because both event and stadium classes have the name and code attributes, you must specify the attributes to inherit using the INHERIT clause.

CREATE CLASS soccer_stadium UNDER event, stadium

INHERIT name OF stadium, code OF stadium;

When the two super classes (event and stadium) have the name attribute, if the soccer_stadium class needs to inherit both attributes, it can inherit the name unchanged from the stadium class and the name changed from the event class by using the alias clause of the INHERIT.

The following example shows in which the name attribute of the stadium class is inherited as it is, and that of the event class is inherited as the purpose alias.

ALTER CLASS soccer_stadium

INHERIT name OF event AS purpose;

Deleting a super class

A name conflict may occur again if a super class that explicitly inherited an attribute or method is dropped by using the INHERIT. In this case, you must specify the attribute or method to be explicitly inherited when dropping the super class.

The following example shows how to create the seoul_1988_soccer class by inheriting game, participant and stadium classes from demodb, and delete the participant class from the super class. Because nation_code and host_year are explicitly inherited from the participant class, you must resolve their name conflicts before deleting it from the super class. However, host_year does not need to be specified explicitly because it exists only in the game class.

CREATE CLASS seoul_1988_soccer UNDER game, participant, stadium

INHERIT nation_code OF participant, host_year OF participant;

ALTER CLASS seoul_1988_soccer


INHERIT nation_code OF stadium;

Compatible Domains

When an attribute conflict occurs among two or more super classes, the statement resolving the conflict is not possible only if all attributes have compatible domains.

For example, the class that inherits a super class with the phone attribute of integer type cannot have another super class with the phone attribute of string type. If the types of the phone attributes of the two super classes are both String or Integer, you can add a new super class by resolving the conflict with the INHERIT clause.

Compatibility is checked when inheriting an attribute with the same name, but with the different domain. In this case, the attribute that has a lower class in the class inheritance hierarchy as the domain is automatically inherited. If the domains of the attributes to inherit are compatible, the conflict must be resolved in the class where an inheritance relationship is defined.