How do I set a primary key to an existing table in Oracle?

1

I usually do it directly through the IDE (Sql Developer), but I need to run the script this time.

Assuming the existing table TB_CR_INDICADOR_PERIODO and column COD_CR_INDICADOR_PERIODO as the unique ID column, how could I set this primary key ?

    
asked by anonymous 11.05.2016 / 21:40

1 answer

3

The correct command to add the primary key would be:

ALTER TABLE table_name ADD CONSTRAINT constraint_name PRIMARY KEY (column1, column2, ... column_n);

Applying to your case would be:

ALTER TABLE TB_CR_INDICADOR_PERIODO ADD CONSTRAINT pk_tb_cr_indicador_periodo PRIMARY KEY (COD_CR_INDICADOR_PERIODO);

There may be an error if the table already has some information.

Source: link

    
11.05.2016 / 21:57