Can I rename an attribute by creating a table from a type?

Asked

Viewed 54 times

2

Following the Object-Relational model, I want to create the tables or_medico and or_atendente derived from t_funcionario that I created. Below follows the structure of type:

DROP TYPE t_funcionario FORCE;
CREATE OR REPLACE TYPE t_funcionario AS OBJECT (
    cod_func INTEGER,
    nome_func VARCHAR2(50),
    crm_med VARCHAR2(15),
    escala_func VARCHAR2(12)
);

And the creative method of the tables or_medico and or_atendente

DROP TABLE or_medico CASCADE CONSTRAINTS;
CREATE TABLE or_medico OF t_funcionario (
    PRIMARY KEY (cod_func),
    nome_func NOT NULL,
    UNIQUE crm_med,
    escala_func NOT NULL
) OBJECT IDENTIFIER IS SYSTEM GENERATED;

DROP TABLE or_atendente CASCADE CONSTRAINTS;
CREATE TABLE or_atendente OF t_funcionario (
    PRIMARY KEY (cod_func),
    nome_func NOT NULL,
    escala_func NOT NULL
) OBJECT IDENTIFIER IS SYSTEM GENERATED;

In doing so, the attributes of both tables will end with "func", as they derive from t_funcionario. Would it be possible to change the name of the attributes so that they are specific to each table? Example:

Table or_medico has the attributes cod_med, nome_med, escala_med and the table or_atendente has the attributes cod_atendente, nome_atendente, escala_atendente?

  • I believe that this cannot be done because the attribute of "type" will prevail but the creation of the table would already qualify , take the "func" of the primitive type and would be or_medico.name , however use "types" in database columns can make it impossible to query via sql in some languages on a front end. However your question is very interesting.

  • @Motta, I asked the same question in Stackoverflow in English and I was told the same, that I could not change the name of the attribute, because the name coming from the type would prevail. I will answer this question with the link to my question in English.

1 answer

0


This question was asked on the Stackoverflow English forum.

Follow the link to the answer and discussions about my question: https://stackoverflow.com/questions/64635677/can-i-change-an-attribute-name-from-a-table-derived-from-a-type?noredirect=1#comment114285705_64635677

In short, the attribute could not be renamed. When trying to use the command

ALTER TABLE ... RENAME COLUMN...

would return an error saying it was impossible to do the operation. The most appropriate thing to do would be to remove the suffix "_func" from the type attributes to generalize them and apply to all derived tables of the type.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.