-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointApp_tablescript.sql
233 lines (199 loc) · 5.85 KB
/
PointApp_tablescript.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
--GO
--CREATE DATABASE PointAppDB
GO
use PointAppDB
go
-- student table
create table student
(
studentid int identity(1,1) not null,
firstname nvarchar(30) not null,
lastname nvarchar(30),
middlename nvarchar(30) not null,
grade int,
active nchar(1) DEFAULT 'Y'
);
go
alter table student add constraint student_pk primary key (studentid);
------------------------------------
-- contact table
-- contact information for all member
go
create table contact
(
contactid int identity(1,1) not null,
firstname nvarchar(30) not null,
lastname nvarchar(30) not null,
middlename nvarchar(30),
address nvarchar(100) not null,
altaddress nvarchar(100),
city nvarchar(30) not null,
state nchar(2) default 'CO',
zip nvarchar(10),
homephone nvarchar(20),
workphone nvarchar(20),
mobilephone nvarchar(20)
);
go
alter table contact add constraint contact_pk primary key (contactid);
--------------------------------
-- contact_email table
-- multiple email
go
create table contactemail
(
contactemailid int identity(1,1) not null,
contactid int,
emailaddress nvarchar(30)
);
go
alter table contactemail add constraint contactemail_pk primary key (contactemailid);
go
alter table contactemail add constraint contactemail_contact_fk foreign key (contactid) references contact(contactid);
-------------------------------------------
-- activity table
-- member has join in different activity such as volunteer, administrative member, jazz, etc.
GO
CREATE TABLE activity (
activityid INT identity(1,1) NOT NULL,
actname NVARCHAR(30) NOT NULL,
CONSTRAINT activity_pk PRIMARY KEY (activityid)
);
-----------------------
-- session_type table
-- event type including pizza, empty bowl
go
create table sessiontype
(
sessiontypeid int identity(1,1) not null,
typename nvarchar(50) not null,
note nvarchar(250)
);
go
alter table sessiontype add constraint sessiontype_pk primary key (sessiontypeid);
-----------------------------
-- approle table
-- user role
go
create table approle
(
approleid int identity(1,1) not null,
rolename nvarchar(50) not null,
note nvarchar(250)
);
go
alter table approle add constraint approle_pk primary key (approleid);
-----------------------------------------
-- member table
-- member status is parent or student
go
create table member
(
memberid int identity(1,1) not null,
username nvarchar(30) not null,
userpass nvarchar(32) not null,
passphrase nvarchar(50) not null,
memberstatus nvarchar(10) not null,
approleid int default 2
);
go
alter table member add constraint member_pk primary key (memberid);
go
alter table member add constraint member_approle_fk foreign key (approleid) references approle(approleid);
---------------------------
-- member2student
-- assign student
go
create table member2student
(
memberid int not null,
studentid int not null
);
go
alter table member2student add constraint member2student_pk primary key (memberid, studentid);
go
alter table member2student add constraint member2student_member_fk foreign key (memberid) references member(memberid);
go
alter table member2student add constraint member2student_student_fk foreign key (studentid) references student(studentid);
---------------------------
-- member2contact
-- assign contact
GO
CREATE TABLE [dbo].[member2contact] (
[memberid] INT NOT NULL,
[contactid] INT NOT NULL,
CONSTRAINT [member2contact_pk] PRIMARY KEY ([memberid], [contactid]),
CONSTRAINT [member2contact_member_fk] FOREIGN KEY ([memberid]) REFERENCES [dbo].[member] ([memberid]),
CONSTRAINT [member2contact_contact_fk] FOREIGN KEY ([contactid]) REFERENCES [dbo].[contact] ([contactid])
);
---------------------------
-- member2dependent
-- assign dependent
GO
CREATE TABLE [dbo].[member2dependent] (
[memberid] INT NOT NULL,
[dependentid] INT NOT NULL,
CONSTRAINT [member2dependent_pk] PRIMARY KEY ([memberid], [dependentid]),
CONSTRAINT [member2dependent_member_fk] FOREIGN KEY ([memberid]) REFERENCES [dbo].[member] ([memberid]),
CONSTRAINT [member2dependent_dependent_fk] FOREIGN KEY ([dependentid]) REFERENCES [dbo].[member] ([memberid])
);
--------------------------------------
-- session_cal table
-- session calendar
go
create table sessioncal
(
sessioncalid int identity(1,1) not null,
sessiondate date,
sessiontypeid int,
sessionnum int,
sessionamt money,
sessionpoint int default 0
);
go
alter table sessioncal add constraint sessioncal_pk primary key (sessioncalid);
go
alter table sessioncal add constraint sessioncal_type_fk foreign key (sessiontypeid) references sessiontype(sessiontypeid);
-----------------------
-- signup table
go
create table signup
(
signupid int identity(1,1) not null,
memberid int,
sessioncalid int,
pointearn int default 0,
isshow nchar(1)
);
go
alter table signup add constraint signup_pk primary key (signupid);
go
alter table signup add constraint signup_member_fk foreign key (memberid) references member(memberid);
go
alter table signup add constraint signup_sessioncal_fk foreign key (sessioncalid) references sessioncal(sessioncalid);
---------------------------------------
-- member2activity table
GO
CREATE TABLE [dbo].[member2activity]
(
[memberid] INT NOT NULL,
[activityid] INT NOT NULL,
CONSTRAINT [member2activity_pk] PRIMARY KEY ([memberid], [activityid]),
CONSTRAINT [member2activity_member_fk] FOREIGN KEY ([memberid]) REFERENCES [dbo].[member] ([memberid]),
CONSTRAINT [member2activity_act_fk] FOREIGN KEY ([activityid]) REFERENCES [dbo].[activity] ([activityid])
);
-------------------------
-- fee_request table
go
create table feerequest
(
feerequestid int identity(1,1) not null,
memberid int,
requestdate date,
requestamt money,
pointbal int default 0
);
go
alter table feerequest add constraint feerequest_pk primary key (feerequestid);
go
alter table feerequest add constraint feerequest_member_fk foreign key (memberid) references member(memberid);