-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLQuery_Drill_p73.sql
More file actions
56 lines (40 loc) · 1.58 KB
/
SQLQuery_Drill_p73.sql
File metadata and controls
56 lines (40 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
USE db_zoo;
SELECT * FROM tbl_habitat;
SELECT species_name FROM tbl_species WHERE species_order = 3;
SELECT nutrition_type FROM tbl_nutrition WHERE nutrition_cost <= 600.00;
SELECT species_name
FROM tbl_species
WHERE species_nutrition BETWEEN 2202 AND 2206;
SELECT species_name AS 'Species Name:', nutrition_type AS 'Nutrition Type: '
FROM tbl_species t1
INNER JOIN tbl_nutrition t2 ON t2.nutrition_id = t1.species_nutrition
SELECT species_name, specialist_fname, specialist_lname, specialist_contact
FROM tbl_specialist
INNER JOIN tbl_care ON tbl_specialist.specialist_id = care_specialist
INNER JOIN tbl_species ON care_id = species_care
WHERE species_name = 'penguin';
CREATE TABLE person (
person_id INT PRIMARY KEY NOT NULL IDENTITY(1,1),
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL,
);
CREATE TABLE contact (
contact_id INT PRIMARY KEY NOT NULL IDENTITY(1,1),
person_id INT NOT NULL CONSTRAINT fk_person_id FOREIGN KEY REFERENCES person(person_id) ON UPDATE CASCADE ON DELETE CASCADE,
street VARCHAR(100) NOT NULL,
zipcode INT NOT NULL,
phone_number VARCHAR(20) NOT NULL
);
INSERT INTO person (first_name, last_name)
VALUES
('Michelle', 'Smith'),
('Sarah', 'Curtis'),
('Valerie', 'Imperial');
INSERT INTO contact (person_id,street, zipcode, phone_number)
VALUES
(1,'123 Flower St', 32223, '303-555-5555'),
(2,'456 Circle Ave', 34423, '303-748-3049'),
(3,'789 Hampden Ave', 32443, '720-374-1398');
SELECT first_name, last_name, phone_number
FROM person
INNER JOIN contact ON contact.person_id = person.person_id;