2
I am creating primary and foreign keys with the NOT NULL Constraint in Postgresql, only the way I am doing this is going in the properties in the table and manually setting the keys as NOT NULL, I would like to do this through the table creation codes.
Below are some tables of my bank so that they can understand and help me in this my doubt
CREATE TABLE endereco_fornecedor (
cd_endereco_fornecedor SERIAL PRIMARY KEY,
cidade VARCHAR(30),
bairro VARCHAR(30),
endereco VARCHAR(30),
numero_endereco INT
)
CREATE TABLE telefone_fornecedor (
cd_telefone_fornecedor SERIAL PRIMARY KEY,
telefone_fornecedor VARCHAR(15)
)
CREATE TABLE fornecedor (
cd_fornecedor SERIAL PRIMARY KEY,
cd_endereco_fornecedor INT,
cd_telefone_fornecedor INT,
cnpj_fornecedor VARCHAR(18),
nome_fornecedor VARCHAR(30),
email_fornecedor VARCHAR(50),
foreign key (cd_endereco_fornecedor) references endereco_fornecedor (cd_endereco_fornecedor),
foreign key (cd_telefone_fornecedor) references telefone_fornecedor (cd_telefone_fornecedor)
)
You want the cd_address_vendor and cd_phone_vendor fields not to be null?
– Daniel Mendes
Yes,
NOT NULL
for all keys.– user179501