-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pedrodanieljardim
committed
Dec 29, 2020
1 parent
730a693
commit 312287a
Showing
5 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |