-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sql
More file actions
78 lines (61 loc) · 1.53 KB
/
script.sql
File metadata and controls
78 lines (61 loc) · 1.53 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- Task 1
select * from parts;
-- Task 2
alter table parts
add unique (code),
alter column code set not null;
-- Task 3
update parts
set description = 'None Available'
where description is null or description = ' ';
-- Task 4
alter table parts
alter column description set not null;
-- Task 5
insert into parts values (null);
insert into parts (id, code, manufacturer_id) values (
54,
'V1-009',
9
);
insert into parts (description,code) values ('None Available','None Available');
DELETE FROM parts
WHERE id IS NULL;
-- Task 6
alter table reorder_options
alter column price_usd set not null,
alter column quantity set not null;
-- Task 7
alter table reorder_options
add check (price_usd > 0 and quantity > 0);
-- Task 8
alter table reorder_options
add check (price_usd/quantity between 0.02 and 25);
-- Task 9
alter table parts
add primary key (id);
alter table reorder_options
add foreign key (part_id) references parts(id);
-- Task 10
alter table locations
add check (qty > 0);
-- Task 11
alter table locations
add primary key (part_id, location);
-- Task 12
delete from locations
where part_id = 54;
alter table locations
add foreign key (part_id) references parts(id);
-- Task 13
alter table parts
add foreign key (manufacturer_id) references manufacturers(id);
-- Task 14
insert into manufacturers values(11,'Pip-NNC Industrial');
-- Task 15
update parts
set manufacturer_id = 11
where manufacturer_id in (1,2);
SELECT constraint_name, table_name, column_name
from information_schema.key_column_usage
where table_name = 'manufacturers';