0
I have a City, State and Country Database. But I want to add Cities to my table and it doesn’t always contain a state to be referenced.
However, every city is located in a country.
My question is: can I create a relationship in which the city that has not been, but which may be related to some country?
CREATE TABLE cidade
(
id_cidade integer NOT NULL,
id_estado integer NOT NULL,
nome character varying(120) NOT NULL,
CONSTRAINT cidade_pkey PRIMARY KEY (id_cidade),
CONSTRAINT fk_cidade_estado FOREIGN KEY (id_estado)
REFERENCES estado (id_estado) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
Which database are you using? Is mysql?
– Guilherme Nascimento
I used Postgresql
– Victor Henrique
I edited the question and added the postgresql tag and also removed the closing vote. Good luck!
– Guilherme Nascimento