| 1 | drop table if exists people cascade;
|
|---|
| 2 | drop table if exists accused cascade;
|
|---|
| 3 | drop table if exists witness cascade;
|
|---|
| 4 | drop table if exists victim cascade;
|
|---|
| 5 | drop table if exists policeman cascade;
|
|---|
| 6 | drop table if exists officer cascade;
|
|---|
| 7 | drop table if exists sector_of_interal_affairs cascade;
|
|---|
| 8 | drop table if exists police_station cascade;
|
|---|
| 9 | drop table if exists crime_case cascade;
|
|---|
| 10 | drop table if exists statements cascade;
|
|---|
| 11 | drop table if exists type_of_crime cascade;
|
|---|
| 12 | drop table if exists solved_case cascade;
|
|---|
| 13 | drop table if exists evidence cascade;
|
|---|
| 14 | drop table if exists mentions_evidence cascade;
|
|---|
| 15 | drop table if exists accused_for cascade;
|
|---|
| 16 | drop table if exists case_belongs_to_type_of_crime cascade;
|
|---|
| 17 |
|
|---|
| 18 | drop schema if exists project cascade;
|
|---|
| 19 |
|
|---|
| 20 | create schema project;
|
|---|
| 21 |
|
|---|
| 22 | create table People (
|
|---|
| 23 | pe_id bigint primary key,
|
|---|
| 24 | first_name varchar(255) NOT NULL,
|
|---|
| 25 | last_name varchar(255) NOT NULL,
|
|---|
| 26 | gender varchar(10) NOT NULL,
|
|---|
| 27 | address varchar(4000) NOT NULL,
|
|---|
| 28 | picture varchar(4000) NOT NULL,
|
|---|
| 29 | contact varchar(30) NOT NULL,
|
|---|
| 30 | embg char(13) unique,
|
|---|
| 31 | date_of_birth date NOT NULL,
|
|---|
| 32 | country varchar(255) NOT NULL,
|
|---|
| 33 | nationality varchar(255) NOT NULL
|
|---|
| 34 | );
|
|---|
| 35 | create table Sector_of_interal_affairs(
|
|---|
| 36 | s_id bigint primary key,
|
|---|
| 37 | city varchar(255) NOT NULL
|
|---|
| 38 | );
|
|---|
| 39 | create table Accused(
|
|---|
| 40 | pe_id bigint primary key references people(pe_id)
|
|---|
| 41 | );
|
|---|
| 42 | create table Witness(
|
|---|
| 43 | pe_id bigint primary key references people(pe_id)
|
|---|
| 44 | );
|
|---|
| 45 | create table Victim(
|
|---|
| 46 | pe_id bigint primary key references people(pe_id)
|
|---|
| 47 | );
|
|---|
| 48 |
|
|---|
| 49 | create table Officer(
|
|---|
| 50 | pe_id bigint primary key references people(pe_id),
|
|---|
| 51 | o_date_of_employment date NOT NULL,
|
|---|
| 52 | o_badge_no bigint NOT NULL,
|
|---|
| 53 | o_password varchar(255) NOT NULL
|
|---|
| 54 | );
|
|---|
| 55 |
|
|---|
| 56 | create table Police_station (
|
|---|
| 57 | p_id bigint primary key,
|
|---|
| 58 | p_address varchar(4000) NOT NULL,
|
|---|
| 59 | s_id bigint NOT NULL references Sector_of_interal_affairs(s_id),
|
|---|
| 60 | pe_id bigint NOT NULL references Officer(pe_id)
|
|---|
| 61 | );
|
|---|
| 62 | create table Policeman(
|
|---|
| 63 | pe_id bigint primary key references people(pe_id),
|
|---|
| 64 | badge_no bigint NOT NULL,
|
|---|
| 65 | p_date_of_employment date NOT NULL,
|
|---|
| 66 | rank smallint NOT NULL,
|
|---|
| 67 | p_id bigint NOT NULL references police_station(p_id),
|
|---|
| 68 | p_password varchar(255) NOT NULL
|
|---|
| 69 | );
|
|---|
| 70 | create table Crime_case (
|
|---|
| 71 | c_id bigint primary key,
|
|---|
| 72 | c_name varchar(255) NOT NULL,
|
|---|
| 73 | opening_date date NOT NULL,
|
|---|
| 74 | c_status varchar(2) NOT NULL,
|
|---|
| 75 | p_id bigint NOT NULL references Police_station(p_id)
|
|---|
| 76 | );
|
|---|
| 77 | create table Statements (
|
|---|
| 78 | s_id bigint primary key,
|
|---|
| 79 | statement_date date NOT NULL,
|
|---|
| 80 | description varchar(10000) NOT NULL,
|
|---|
| 81 | incident_timestamp timestamp NOT NULL,
|
|---|
| 82 | incident_place varchar(4000) NOT NULL,
|
|---|
| 83 | c_id bigint NOT NULL references Crime_case(c_id),
|
|---|
| 84 | pe_id bigint NOT NULL references Policeman(pe_id),
|
|---|
| 85 | victim_pe_id bigint NOT NULL references Victim(pe_id),
|
|---|
| 86 | witness_pe_id bigint NOT NULL references Witness(pe_id)
|
|---|
| 87 | );
|
|---|
| 88 | create table Type_of_crime (
|
|---|
| 89 | t_id bigint primary key,
|
|---|
| 90 | t_name varchar(255) NOT NULL
|
|---|
| 91 | );
|
|---|
| 92 | create table Solved_case (
|
|---|
| 93 | sc_description varchar(10000) NOT NULL,
|
|---|
| 94 | final_document varchar(40000) NOT NULL, -- added as a picture or a scan
|
|---|
| 95 | c_id bigint NOT NULL references Crime_case(c_id),
|
|---|
| 96 | date_of_closing date NOT NULL,
|
|---|
| 97 | constraint solved_case_pkey primary key (c_id,date_of_closing)
|
|---|
| 98 | );
|
|---|
| 99 | create table Evidence (
|
|---|
| 100 | e_id bigint primary key,
|
|---|
| 101 | e_name varchar(255) NOT NULL,
|
|---|
| 102 | e_type varchar(255) NOT NULL,
|
|---|
| 103 | is_found boolean NOT NULL,
|
|---|
| 104 | e_picture varchar(100000) NOT NULL
|
|---|
| 105 | );
|
|---|
| 106 | create table Mentions_evidence (
|
|---|
| 107 | s_id bigint references Statements(s_id),
|
|---|
| 108 | e_id bigint references Evidence(e_id),
|
|---|
| 109 | constraint Mentions_evidence_pkey primary key(s_id,e_id)
|
|---|
| 110 | );
|
|---|
| 111 | create table Accused_for (
|
|---|
| 112 | accused_pe_id bigint references Accused(pe_id),
|
|---|
| 113 | c_id bigint references Crime_case(c_id),
|
|---|
| 114 | constraint Accused_For_pkey primary key (accused_pe_id, c_id)
|
|---|
| 115 | );
|
|---|
| 116 | create table Case_belongs_to_type_of_crime (
|
|---|
| 117 | c_id bigint references Crime_case(c_id),
|
|---|
| 118 | t_id bigint references Type_of_crime(t_id),
|
|---|
| 119 | constraint Case_belongs_to_type_of_crime_pkey primary key (c_id, t_id)
|
|---|
| 120 | ); |
|---|