-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChalla_MeghnathReddy_IP_Task4.sql
169 lines (106 loc) · 6.09 KB
/
Challa_MeghnathReddy_IP_Task4.sql
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
DROP TABLE IF EXISTS Employees ;
DROP TABLE IF EXISTS Volunteers ;
DROP TABLE IF EXISTS Donors ;
DROP TABLE IF EXISTS Emergency_Details;
DROP TABLE IF EXISTS Needs ;
DROP TABLE IF EXISTS Insurance_Policy ;
DROP TABLE IF EXISTS Cares ;
DROP TABLE IF EXISTS Serves ;
DROP TABLE IF EXISTS Reports ;
DROP TABLE IF EXISTS Expenses ;
DROP TABLE IF EXISTS Check_1 ;
DROP TABLE IF EXISTS Credit_Card ;
DROP TABLE IF EXISTS Sponsors ;
DROP TABLE IF EXISTS Affliated ;
DROP TABLE IF EXISTS Teams ;
DROP TABLE IF EXISTS Business ;
DROP TABLE IF EXISTS Church ;
DROP TABLE IF EXISTS External_Donor ;
DROP TABLE IF EXISTS Ex_check ;
DROP TABLE IF EXISTS Ex_creditcard ;
DROP TABLE IF EXISTS Client ;
DROP TABLE IF EXISTS External_Org ;
DROP TABLE IF EXISTS Person;
-----CREATE TABLES------------
CREATE Table Person (SSN INT PRIMARY KEY, Name Varchar(30) NOT NULL,
Birthdate DATE NOT NULL, Race Varchar(20) NOT NULL, Gender Varchar(10) NOT NULL,
Profession Varchar(20) NOT NULL, Mail_address Varchar(100),
Email_address Varchar(30), Home_phone INT NOT NULL,
Work_phone INT NOT NULL, Cell_phone INT NOT NULL, Mailing_list INT NOT NULL);
CREATE TABLE External_Org (Org_Name Varchar (20) PRIMARY KEY,
Org_address Varchar (30) NOT NULL, Org_Number INT NOT NULL, Org_Contact Varchar(20) NOT NULL);
CREATE TABLE Client (SSN INT PRIMARY KEY,
Doctor_Name Varchar(30) NOT NULL,Attor_Name Varchar(30) NOT NULL, Doctor_phone INT NOT NULL,
Attor_phone INT NOT NULL,
Date_assigned DATE NOT NULL,
FOREIGN KEY (SSN) REFERENCES PERSON(SSN) );
CREATE TABLE Employees (SSN INT PRIMARY KEY, E_Salary FLOAT NOT NULL,
M_Status Varchar(20), HireDate DATE NOT NULL,
FOREIGN KEY (SSN) REFERENCES PERSON(SSN) ) ;
CREATE TABLE Volunteers (SSN INT PRIMARY KEY, Joining_Date DATE NOT NULL,
Training_Date DATE NOT NULL,Training_Loc Varchar(30) NOT NULL,
FOREIGN KEY (SSN) REFERENCES PERSON(SSN) );
CREATE TABLE Donors (SSN INT PRIMARY KEY, Anonymous Varchar(30) NOT NULL,FOREIGN KEY (SSN) REFERENCES PERSON(SSN) );
CREATE TABLE Emergency_Details (SSN INT, Emer_Name Varchar(30), Contact_Info INT, Relationship Varchar(30) ,
PRIMARY KEY (Emer_Name, Contact_Info,Relationship),
FOREIGN KEY (SSN) REFERENCES PERSON(SSN) );
CREATE TABLE Needs (SSN INT, Type Varchar (30) ,
Imp_Value INT NOT NULL,FOREIGN KEY (SSN) REFERENCES PERSON(SSN),
CONSTRAINT Value_check CHECK (Imp_Value between 1 and 10), PRIMARY KEY (SSN,Type, Imp_Value) );
CREATE TABLE Insurance_Policy (SSN INT NOT NULL, Policy_id INT PRIMARY KEY, Provider_id INT NOT NULL,
Provider_address Varchar(100) NOT NULL,
Type VARCHAR(30) NOT NULL,
FOREIGN KEY (SSN) REFERENCES PERSON(SSN));
CREATE TABLE Teams ( T_Name Varchar(30) PRIMARY KEY, Type Varchar(20) NOT NULL, Date_T INT NOT NULL);
CREATE TABLE Cares (SSN INT, T_Name Varchar(30),C_ActiveState INT NOT NULL ,
FOREIGN KEY (SSN) REFERENCES PERSON(SSN) , FOREIGN KEY (T_Name) REFERENCES Teams(T_Name) );
CREATE TABLE Serves (SSN INT, FOREIGN KEY (SSN) REFERENCES PERSON(SSN), T_Name Varchar(30),
FOREIGN KEY (T_Name) REFERENCES Teams(T_Name) ,Hours INT NOT NULL, Active_State INT NOT NULL,
Specific_Month Varchar (20) NOT NULL);
CREATE TABLE Reports (SSN INT, T_Name Varchar(30),
R_DATE DATE NOT NULL, Desc_1 Varchar(30) NOT NULL, FOREIGN KEY (SSN) REFERENCES PERSON(SSN) ,
FOREIGN KEY (T_Name) REFERENCES Teams(T_Name), PRIMARY KEY (T_Name,SSN) );
CREATE TABLE Expenses (SSN INT , FOREIGN KEY (SSN) REFERENCES PERSON(SSN),Amount FLOAT NOT NULL,
Desc_1 Varchar (30) NOT NULL,Expense_Date INT NOT NULL,PRIMARY KEY (Amount,Desc_1,Expense_Date,SSN));
CREATE TABLE Check_1(SSN INT, FOREIGN KEY (SSN) REFERENCES PERSON(SSN),
C_Date DATE , Amount FLOAT , D_Type Varchar(30), Campaign_Name Varchar(30),Cheque_Number INT NOT NULL,
PRIMARY KEY (SSN, C_Date, Amount, D_Type, Campaign_Name, Cheque_Number));
CREATE TABLE Sponsors (T_Name Varchar(30) , FOREIGN KEY (T_Name) REFERENCES Teams(T_Name) ,
Org_Name Varchar (20) , FOREIGN KEY (Org_Name) REFERENCES External_Org (Org_Name));
CREATE TABLE Affliated (SSN INT, FOREIGN KEY (SSN) REFERENCES PERSON(SSN),
Org_Name Varchar (20),
FOREIGN KEY (Org_Name) REFERENCES External_Org (Org_Name),PRIMARY KEY (SSN) );
CREATE TABLE Business (Org_Name Varchar (20) PRIMARY KEY,
FOREIGN KEY (Org_Name) REFERENCES External_Org (Org_Name),
Type Varchar(30) NOT NULL, Size INT NOT NULL,Website Varchar (50) NOT NULL);
CREATE TABLE Church (Org_Name Varchar (20) PRIMARY KEY,
FOREIGN KEY (Org_Name) REFERENCES External_Org (Org_Name),
R_affliation Varchar (20) NOT NULL);
CREATE TABLE External_Donor (Org_Name Varchar (20) PRIMARY KEY,
FOREIGN KEY (Org_Name) REFERENCES External_Org (Org_Name),
Anonymous Varchar(20) NOT NULL);
CREATE TABLE Ex_check (Org_Name Varchar (20), FOREIGN KEY (Org_Name) REFERENCES External_Org (Org_Name),
Ex_Date DATE,Ex_Amount INT,Ex_Type Varchar (30),
Campaign_Name Varchar(30) ,Cheque_Number INT NOT NULL,
PRIMARY KEY (Org_Name, Ex_Date, Ex_Amount, Ex_Type, Campaign_Name));
CREATE TABLE Ex_creditcard (Org_Name Varchar (20), FOREIGN KEY (Org_Name) REFERENCES External_Org (Org_Name),
ExCC_Date DATE, ExCC_Amount INT, ExCC_Type Varchar(30), ExCCCampaign_Name Varchar(30),
ExCard_number INT NOT NULL, ExCard_Type Varchar (20) NOT NULL,
Ex_Exp_Date DATE NOT NULL, PRIMARY KEY (Org_Name, ExCC_Date, ExCC_Amount, ExCC_Type, ExCCCampaign_Name));
------INDEX------------------------
DROP INDEX IF EXISTS Needs.Type_V;
CREATE INDEX Type_V on Needs(Type,Imp_Value);
DROP INDEX IF EXISTS Insurance_Policy.I_Type;
CREATE INDEX I_Type on Insurance_Policy(Type);
DROP INDEX IF EXISTS Teams.T_Date;
CREATE INDEX T_Date on Teams(Date_T);
DROP INDEX IF EXISTS Cares.C_TName;
CREATE INDEX C_TName on Cares(T_Name);
DROP INDEX IF EXISTS Cares.C_SSN;
CREATE INDEX C_SSN on Cares(SSN);
DROP INDEX IF EXISTS Expense.E_Date;
CREATE INDEX E_Date on Expenses(Expense_Date);
DROP INDEX IF EXISTS Sponsors.Sp_OrgName;
CREATE INDEX Sp_OrgName on Sponsors(Org_Name);
DROP INDEX IF EXISTS Serves.T_Index;
CREATE INDEX T_Index on Serves(T_Name);