-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
73 lines (62 loc) · 1.85 KB
/
Copy pathschema.sql
File metadata and controls
73 lines (62 loc) · 1.85 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
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/y8XlYU
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
CREATE TABLE participants (
case_participant_id bigint,
age_at_incident integer,
gender varchar,
race varchar,
age_bins varchar,
CONSTRAINT pk_participants PRIMARY KEY (
case_participant_id
)
);
CREATE TABLE courts (
court_id varchar,
court_facility varchar,
court_name varchar,
CONSTRAINT pk_courts PRIMARY KEY (
court_id
)
);
CREATE TABLE offenses (
offense_id integer,
offense_category varchar,
CONSTRAINT pk_offenses PRIMARY KEY (
offense_id
)
);
CREATE TABLE sentences (
sentence_id integer,
sentence_type varchar,
commitment_term float,
commitment_unit varchar,
month float,
year float,
CONSTRAINT pk_sentences PRIMARY KEY (
sentence_id
)
);
CREATE TABLE results (
case_participant_id bigint,
court_id varchar,
offense_id integer,
sentence_id integer,
case_id bigint,
charge_disposition varchar,
length_of_case_in_days bigint,
disposition_charged_offense_title varchar,
charge_count integer,
disposition_charged_class varchar,
sentence_date date,
incident_begin_date date,
arrest_date date
);
ALTER TABLE results ADD CONSTRAINT fk_results_case_participant_id FOREIGN KEY( case_participant_id )
REFERENCES participants ( case_participant_id );
ALTER TABLE results ADD CONSTRAINT fk_results_court_id FOREIGN KEY( court_id )
REFERENCES courts ( court_id );
ALTER TABLE results ADD CONSTRAINT fk_results_offense_id FOREIGN KEY( offense_id )
REFERENCES offenses ( offense_id );
ALTER TABLE results ADD CONSTRAINT fk_results_sentence_id FOREIGN KEY( sentence_id )
REFERENCES sentences ( sentence_id );