Skip to content

Commit

Permalink
#Resolution - #2622
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodanieljardim committed Dec 29, 2020
1 parent 730a693 commit 312287a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions Database/2622/create_table_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE customers(id int primary key, name varchar(30), street varchar(30), city varchar(30), state varchar(2), credit_limit numeric)
8 changes: 8 additions & 0 deletions Database/2622/create_table_legal_person.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE legal_person(
cnpj char(18),
contact varchar(30),
)

ADD CONSTRAINT id_customers FOREIGN KEY (id_customers) REFERENCES dbo.customers (id)
ALTER TABLE dbo.legal_person ADD id_customers INT NOT NULL
ALTER TABLE dbo.legal_person ADD CONSTRAINT id_customers FOREIGN KEY (id_customers) REFERENCES dbo.customers (id)
7 changes: 7 additions & 0 deletions Database/2622/insert_table-customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
INSERT INTO dbo.customers (id, name, street, city, state, credit_limit)VALUES(1, 'Pedro Daniel', 'Rua Limoeiro', 'Contagem', 'MG', 200000)
INSERT INTO dbo.customers (id, name, street, city, state, credit_limit)VALUES(2, 'Nicolas Diogo Cardoso', 'Acesso Um', 'Porto Alegre', 'RS', 475)
INSERT INTO dbo.customers (id, name, street, city, state, credit_limit)VALUES(3, 'Cecília Olivia Rodrigues', 'Rua Sizuka Usuy', 'Cianorte', 'PR', 3000)
INSERT INTO dbo.customers (id, name, street, city, state, credit_limit)VALUES(4, 'Augusto Fernando Carlos Eduardo Cardoso', 'Rua Baldomiro Koerich', 'Palhoça', 'SC', 1067)
INSERT INTO dbo.customers (id, name, street, city, state, credit_limit)VALUES(5, 'Nicolas Diogo Cardoso', 'Rua Baldomiro Koerich', 'Porto Alegre', 'RS', 465)
INSERT INTO dbo.customers (id, name, street, city, state, credit_limit)VALUES(6, 'Sabrina Heloisa Gabriela Barros','Rua Engenheiro Tito Marques Fernandes', 'Porto Alegre', 'RS', 4312)
INSERT INTO dbo.customers (id, name, street, city, state, credit_limit)VALUES(4, 'Joaquim Diego Lorenzo Araújo','Rua Vitorino', 'Novo Hamburgo', 'RS', 234)
2 changes: 2 additions & 0 deletions Database/2622/insert_table_legal_person.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO dbo.legal_person(id_customers, cnpj, contact)VALUES(4, '85883842000191', '99767-0562')
INSERT INTO dbo.legal_person(id_customers, cnpj, contact)VALUES(5, '47773848000117', '99100-8965')
1 change: 1 addition & 0 deletions Database/2622/solution_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT name FROM customers c WHERE (c.id LIKE (SELECT id_customers FROM legal_person WHERE id_customers LIKE c.id))

0 comments on commit 312287a

Please sign in to comment.