Sunday, March 25, 2012

alter table.. foreign key

I want to add a foreign key codnegozio references to negozio.idnegozio on table cliente
The table cliente is:
CREATE TABLE Cliente
(User_id VARCHAR(10)PRIMARY KEY ,
Nome VARCHAR2(15) NOT NULL ,
Cognome VARCHAR2(15) NOT NULL,
Indirizzo VARCHAR2(50) NOT NULL ,
CAP NUMBER(6) NOT NULL,
Citt VARCHAR2(50) NOT NULL ,
Provincia VARCHAR2(50) NOT NULL,
Password VARCHAR2(8) NOT NULL ,
Email VARCHAR2(100) NOT NULL,
Credito NUMBER(6) NOT NULL,
Carta_credito NUMBER(10))

and the table negozio is:
CREATE TABLE Negozio
(IdNegozio NUMBER(8) PRIMARY KEY auto-increment,
Ragione_Sociale VARCHAR2(20) NOT NULL,
Indirizzo VARCHAR2(15) NOT NULL ,
CAP NUMBER(6) NOT NULL,
Citt VARCHAR2(15) NOT NULL ,
Provincia VARCHAR2(15) NOT NULL,
Email VARCHAR2(15) NOT NULL)

what' s can I do?
Thank you ElisaIs this Oracle? If so:

alter table Cliente add (codnegozio NUMBER(8));

alter table Cliente add constraint my_constraint_name foreign key (codnegozio) references Negozio;

No comments:

Post a Comment