Hello Friends of Oracle
I would like to know how to add a column in a PK.
If someone can help me thank you.
ATT,
Dan
Add column in a PK
-
- Rank: DBA Sênior
- Posts: 372
- Joined: Tue, 24 Jan 2006 3:33 pm
- Location: Palmas - TO
- Contact:
If you have created your table without restriction, that is, without the primary key, do the following:
or if the table already has the primary key but you want to add a column in the primary key, You need to delete the restriction first and then rebuild it:
CAUTION! I did not run this script! You better test the syntax first.
until
Gilberto
CREATE TABLE CHAVE(
CHAVE_PRIMARIA NUMBER NOT NULL,
DESCRICAO VARCHAR2(60)
);
ALTER TABLE CHAVE ADD CONSTRAINT CHAVE_PK PRIMARY KEY (CHAVE_PRIMARIA);
or if the table already has the primary key but you want to add a column in the primary key, You need to delete the restriction first and then rebuild it:
CREATE TABLE CHAVE(
CHAVE_PRIMARIA NUMBER NOT NULL,
CHAVE_SECUNDARIA VARCHAR2(5) NOT NULL,
DESCRICAO VARCHAR2(60),
CONSTRAINT CHAVE_PK PRIMARY KEY (CHAVE_PRIMARIA ) )
);
ALTER TABLE CHAVE DROP CONSTRAINT CHAVE_PK;
ALTER TABLE CHAVE ADD CONSTRAINT CHAVE_PK PRIMARY KEY (CHAVE_PRIMARIA, CHAVE_SECUNDARIA);
until
Gilberto
-
- Information
-
Who is online
Users browsing this forum: No registered users and 2 guests