-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.sql
More file actions
10 lines (10 loc) · 1.41 KB
/
create.sql
File metadata and controls
10 lines (10 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
create table cargos (id int8 generated by default as identity, nome varchar(60) not null, id_departamento_fk int8 not null, primary key (id));
create table departamentos (id int8 generated by default as identity, nome varchar(60) not null, primary key (id));
create table enderecos (id int8 generated by default as identity, bairro varchar(255) not null, cep varchar(9) not null, cidade varchar(255) not null, complemento varchar(255), logradouro varchar(255) not null, numero int4 not null, uf varchar(2) not null, primary key (id));
create table funcionarios (id int8 generated by default as identity, data_entrada DATE not null, data_saida DATE, nome varchar(255) not null, salario DECIMAL(7,2) DEFAULT 0.00 not null, cargo_id_fk int8 not null, endereco_id_fk int8, primary key (id));
alter table if exists cargos add constraint UK_gseglqgqp16hn9j3pqn06m8oy unique (nome);
alter table if exists departamentos add constraint UK_gmqvdqbwy3c9wja72wnfd01kc unique (nome);
alter table if exists funcionarios add constraint UK_jmxa8whte99rhpgvxq8a28vhm unique (nome);
alter table if exists cargos add constraint FKtjl420ddyfp607dq6vo67blqi foreign key (id_departamento_fk) references departamentos;
alter table if exists funcionarios add constraint FKo4oltd663g3w8cd4iiw5ggina foreign key (cargo_id_fk) references cargos;
alter table if exists funcionarios add constraint FK3qpeu6e4lxnghbisl8hwqm0oe foreign key (endereco_id_fk) references enderecos;