-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_creation_project_script.sql
698 lines (574 loc) · 18.7 KB
/
table_creation_project_script.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
-- Table: answerthread
-- DROP TABLE answerthread;
CREATE TABLE answerthread
(
question_discussionforumid integer NOT NULL,
answerid integer NOT NULL,
immediateparentanswerid integer,
answer character varying(3000),
date date,
numberofupvotes integer,
numberofdownvotes integer,
replierid integer NOT NULL,
CONSTRAINT answerthread_pkey PRIMARY KEY (answerid),
CONSTRAINT fk_answerthread_ans_id FOREIGN KEY (immediateparentanswerid)
REFERENCES answerthread (answerid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_answerthread_question_id FOREIGN KEY (question_discussionforumid)
REFERENCES question (discussionforumid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_replier_id FOREIGN KEY (replierid)
REFERENCES researcher (researcherid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE answerthread
OWNER TO postgres;
-- Index: fki_replier_id
-- DROP INDEX fki_replier_id;
CREATE INDEX fki_replier_id
ON answerthread
USING btree
(replierid);
----------------------------------------------------------------------------------------
-- 135960 rows
----------------------------------------------------------------------------------------
-- Table: country
-- DROP TABLE country;
CREATE TABLE country
(
countryid integer NOT NULL,
name character varying(50),
CONSTRAINT country_pkey PRIMARY KEY (countryid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE country
OWNER TO postgres;
----------------------------------------------------------------------------------------
-- 268 rows
----------------------------------------------------------------------------------------
-- Table: department
-- DROP TABLE department;
CREATE TABLE department
(
departmentid integer NOT NULL,
deparmentname character varying(100) NOT NULL,
departmentmajor integer NOT NULL,
universityid integer NOT NULL,
CONSTRAINT department_pkey PRIMARY KEY (departmentid, universityid),
CONSTRAINT fk_department_major_id FOREIGN KEY (departmentmajor)
REFERENCES topics (topicid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE SET NULL,
CONSTRAINT fk_uni_dept_id FOREIGN KEY (universityid)
REFERENCES university (universityid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
WITH (
OIDS=FALSE
);
ALTER TABLE department
OWNER TO postgres;
-- Index: fki_department_major_id
-- DROP INDEX fki_department_major_id;
CREATE INDEX fki_department_major_id
ON department
USING btree
(departmentmajor);
-- Index: fki_uni_dept_id
-- DROP INDEX fki_uni_dept_id;
CREATE INDEX fki_uni_dept_id
ON department
USING btree
(universityid);
-------------------------------------------------------------
-- 756280 rows
-------------------------------------------------------------
-- Table: department_has_projects
-- DROP TABLE department_has_projects;
CREATE TABLE department_has_projects
(
universityid integer NOT NULL,
departmentid integer NOT NULL,
projectid integer NOT NULL,
CONSTRAINT department_has_projects_pkey PRIMARY KEY (universityid, departmentid, projectid),
CONSTRAINT fk_department_has_projects FOREIGN KEY (departmentid, universityid)
REFERENCES department (departmentid, universityid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_dept_project_id FOREIGN KEY (projectid)
REFERENCES projects (projectid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
WITH (
OIDS=FALSE
);
ALTER TABLE department_has_projects
OWNER TO postgres;
-- Index: fki_dept_project_id
-- DROP INDEX fki_dept_project_id;
CREATE INDEX fki_dept_project_id
ON department_has_projects
USING btree
(projectid);
------------------------------------------------------------------------------------
--50 rows
------------------------------------------------------------------------------------
-- Table: journal
-- DROP TABLE journal;
CREATE TABLE journal
(
journalid integer NOT NULL,
name character varying(500),
CONSTRAINT journal_pkey PRIMARY KEY (journalid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE journal
OWNER TO postgres;
-------------------------------------------------------------------
-- 1532 rows
-------------------------------------------------------------------
-- Table: personalweblink
-- DROP TABLE personalweblink;
CREATE TABLE personalweblink
(
linkid integer NOT NULL,
url character varying(200) NOT NULL,
CONSTRAINT personalweblink_pkey PRIMARY KEY (linkid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE personalweblink
OWNER TO postgres;
---------------------------------------------------------------------
-- 850062 rows
---------------------------------------------------------------------
-- Table: profilestats
-- DROP TABLE profilestats;
CREATE TABLE profilestats
(
researcherid integer NOT NULL,
visitorid integer NOT NULL,
visitingdate date,
CONSTRAINT fk_researcher_id FOREIGN KEY (researcherid)
REFERENCES users (userid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT fk_visitor_id FOREIGN KEY (visitorid)
REFERENCES users (userid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
WITH (
OIDS=FALSE
);
ALTER TABLE profilestats
OWNER TO postgres;
-- Index: fki_researcher_id
-- DROP INDEX fki_researcher_id;
CREATE INDEX fki_researcher_id
ON profilestats
USING btree
(researcherid);
-- Index: fki_visitor_id
-- DROP INDEX fki_visitor_id;
CREATE INDEX fki_visitor_id
ON profilestats
USING btree
(visitorid);
----------------------------------------------------------------
-- 899998 rows
----------------------------------------------------------------
-- Table: projects
-- DROP TABLE projects;
CREATE TABLE projects
(
projectid integer NOT NULL,
name character varying(1000),
synopsis character varying(2000),
CONSTRAINT projects_pkey PRIMARY KEY (projectid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE projects
OWNER TO postgres;
--------------------------------------------------------------
-- 50 rows
--------------------------------------------------------------
-- Table: publications
-- DROP TABLE publications;
CREATE TABLE publications
(
publicationid integer NOT NULL,
title character varying(500),
date date,
subtopicid integer NOT NULL,
projectid integer,
abstract character varying(5000),
journalid integer NOT NULL,
publicationviews integer,
numberofcitations integer,
CONSTRAINT publications_pkey PRIMARY KEY (publicationid),
CONSTRAINT fk_publications_journal_id FOREIGN KEY (journalid)
REFERENCES journal (journalid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_publications_projects_id FOREIGN KEY (projectid)
REFERENCES projects (projectid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE publications
OWNER TO postgres;
--------------------------------------------------------------------------
--100766 rows
--------------------------------------------------------------------------
-- Table: publications_has_reference_to_publications
-- DROP TABLE publications_has_reference_to_publications;
CREATE TABLE publications_has_reference_to_publications
(
publications_publicationid integer NOT NULL,
publications_referencepublicationid integer NOT NULL,
CONSTRAINT publications_has_reference_to_publications_pkey PRIMARY KEY (publications_publicationid, publications_referencepublicationid),
CONSTRAINT fk_publications_id FOREIGN KEY (publications_publicationid)
REFERENCES publications (publicationid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_referenced_publication_id FOREIGN KEY (publications_referencepublicationid)
REFERENCES publications (publicationid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE publications_has_reference_to_publications
OWNER TO postgres;
-------------------------------------------------------------------------------------------
--281144 rows
-------------------------------------------------------------------------------------------
-- Table: publications_has_references
-- DROP TABLE publications_has_references;
CREATE TABLE publications_has_references
(
referenceid integer NOT NULL,
publicationid integer NOT NULL,
CONSTRAINT publications_has_references_pkey PRIMARY KEY (referenceid, publicationid),
CONSTRAINT fk_ref_id FOREIGN KEY (referenceid)
REFERENCES publications (publicationid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_reference_id FOREIGN KEY (referenceid)
REFERENCES reference (referenceid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE publications_has_references
OWNER TO postgres;
-------------------------------------------------------------------------------------------
--78128 rows
-------------------------------------------------------------------------------------------
-- Table: publicationstats
-- DROP TABLE publicationstats;
CREATE TABLE publicationstats
(
researcherid integer NOT NULL,
publicationid integer NOT NULL,
visitdate date NOT NULL,
fulltextrequests integer,
CONSTRAINT fk_publication_id FOREIGN KEY (publicationid)
REFERENCES publications (publicationid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT fk_researcherid FOREIGN KEY (researcherid)
REFERENCES researcher (researcherid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE publicationstats
OWNER TO postgres;
-- Index: fki_researcherid
-- DROP INDEX fki_researcherid;
CREATE INDEX fki_researcherid
ON publicationstats
USING btree
(researcherid);
--------------------------------------------------------------------
-- 100766 rows
--------------------------------------------------------------------
-- Table: question
-- DROP TABLE question;
CREATE TABLE question
(
discussionforumid integer NOT NULL,
researcher_researcherid integer NOT NULL,
subtopics_subtopicid integer NOT NULL,
subtopics_topics_topicid integer NOT NULL,
question character varying(1000),
description character varying(2000),
numberofupvotes integer,
numberofdownvotes integer,
CONSTRAINT question_pkey PRIMARY KEY (discussionforumid),
CONSTRAINT fk_discussionforum_researcher_id FOREIGN KEY (researcher_researcherid)
REFERENCES researcher (researcherid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_discussionforum_subtopics_id FOREIGN KEY (subtopics_subtopicid, subtopics_topics_topicid)
REFERENCES subtopics (subtopicid, topics_topicid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE question
OWNER TO postgres;
-----------------------------------------------------------------------------------------------
-- 13596 rows
-----------------------------------------------------------------------------------------------
-- Table: reference
-- DROP TABLE reference;
CREATE TABLE reference
(
referenceid integer NOT NULL,
type character varying(45),
text character varying(45),
CONSTRAINT reference_pkey PRIMARY KEY (referenceid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE reference
OWNER TO postgres;
-------------------------------------------------------------------------
-- 100000 rows
-------------------------------------------------------------------------
-- Table: researcher
-- DROP TABLE researcher;
CREATE TABLE researcher
(
researcherid integer NOT NULL,
universityid integer,
departmentid integer,
achievements character varying(1000),
specialization_id integer,
major integer,
CONSTRAINT researcher_pkey PRIMARY KEY (researcherid),
CONSTRAINT fk_university_id FOREIGN KEY (universityid)
REFERENCES university (universityid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_user_id FOREIGN KEY (researcherid)
REFERENCES users (userid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
WITH (
OIDS=FALSE
);
ALTER TABLE researcher
OWNER TO postgres;
-- Index: fki_university_id
-- DROP INDEX fki_university_id;
CREATE INDEX fki_university_id
ON researcher
USING btree
(universityid);
-------------------------------------------------------------------
--299999 rows
-------------------------------------------------------------------
-- Table: researcher_follows_subtopics
-- DROP TABLE researcher_follows_subtopics;
CREATE TABLE researcher_follows_subtopics
(
researcher_researcherid integer NOT NULL,
subtopics_subtopicid integer NOT NULL,
subtopics_topics_topicid integer NOT NULL,
CONSTRAINT pk_researcher_follower PRIMARY KEY (researcher_researcherid, subtopics_subtopicid, subtopics_topics_topicid),
CONSTRAINT researcher_follows_subtopics_subtopics_subtopicid_fkey FOREIGN KEY (subtopics_subtopicid, subtopics_topics_topicid)
REFERENCES subtopics (subtopicid, topics_topicid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT researcher_id_fk FOREIGN KEY (researcher_researcherid)
REFERENCES researcher (researcherid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE researcher_follows_subtopics
OWNER TO postgres;
-- Index: fki_subtopic_id_fk
-- DROP INDEX fki_subtopic_id_fk;
CREATE INDEX fki_subtopic_id_fk
ON researcher_follows_subtopics
USING btree
(subtopics_subtopicid);
-----------------------------------------------------------------------
-- 794760 rows
-----------------------------------------------------------------------
-- Table: researcher_has_followers
-- DROP TABLE researcher_has_followers;
CREATE TABLE researcher_has_followers
(
researcherid integer NOT NULL,
followerid integer NOT NULL,
CONSTRAINT researcher_has_followers_pkey PRIMARY KEY (researcherid, followerid),
CONSTRAINT follower_id_fk FOREIGN KEY (followerid)
REFERENCES researcher (researcherid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT researcher_id FOREIGN KEY (researcherid)
REFERENCES researcher (researcherid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE researcher_has_followers
OWNER TO postgres;
--------------------------------------------------------------------------------
-- 599999 rows
--------------------------------------------------------------------------------
-- Table: researcher_has_personalweblink
-- DROP TABLE researcher_has_personalweblink;
CREATE TABLE researcher_has_personalweblink
(
linkid integer NOT NULL,
researcherid integer NOT NULL,
CONSTRAINT researcher_has_personalweblink_pkey PRIMARY KEY (linkid, researcherid),
CONSTRAINT fk_linkid FOREIGN KEY (linkid)
REFERENCES personalweblink (linkid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT fk_researcher_weblink_id FOREIGN KEY (researcherid)
REFERENCES researcher (researcherid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
WITH (
OIDS=FALSE
);
ALTER TABLE researcher_has_personalweblink
OWNER TO postgres;
-- Index: fki_researcher_weblink_id
-- DROP INDEX fki_researcher_weblink_id;
CREATE INDEX fki_researcher_weblink_id
ON researcher_has_personalweblink
USING btree
(researcherid);
----------------------------------------------------------------------------------
-- 894281 rows
----------------------------------------------------------------------------------
-- Table: researcher_has_publications
-- DROP TABLE researcher_has_publications;
CREATE TABLE researcher_has_publications
(
researcher_researcherid integer NOT NULL,
publications_publicationid integer NOT NULL,
publication_rank integer,
isadvisor boolean,
CONSTRAINT research_pub_composite_pk PRIMARY KEY (researcher_researcherid, publications_publicationid),
CONSTRAINT publication_id_fk1 FOREIGN KEY (publications_publicationid)
REFERENCES publications (publicationid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT researcher_id_fk_pub FOREIGN KEY (researcher_researcherid)
REFERENCES researcher (researcherid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE researcher_has_publications
OWNER TO postgres;
-- Index: fki_researcher_id_fk_pub
-- DROP INDEX fki_researcher_id_fk_pub;
CREATE INDEX fki_researcher_id_fk_pub
ON researcher_has_publications
USING btree
(researcher_researcherid);
-----------------------------------------------------------------------------
-- 203832 rows
-----------------------------------------------------------------------------
CREATE TABLE subtopics
(
subtopicid integer NOT NULL,
name character varying(100),
topics_topicid integer NOT NULL,
CONSTRAINT subtopics_pkey PRIMARY KEY (subtopicid, topics_topicid),
CONSTRAINT topics_id_fk FOREIGN KEY (topics_topicid)
REFERENCES topics (topicid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE subtopics
OWNER TO postgres;
------------------------------------------------------------------------------
-- 599 rows
------------------------------------------------------------------------------
-- Table: topics
-- DROP TABLE topics;
CREATE TABLE topics
(
topicid integer NOT NULL,
name character varying(100),
CONSTRAINT topics_pkey PRIMARY KEY (topicid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE topics
OWNER TO postgres;
-----------------------------------------------------------------------------
-- 74
-----------------------------------------------------------------------------
-- Table: university
-- DROP TABLE university;
CREATE TABLE university
(
universityid integer NOT NULL,
name character varying(200) NOT NULL,
address character varying(500),
countryid integer,
statename character varying(50),
CONSTRAINT university_pkey PRIMARY KEY (universityid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE university
OWNER TO postgres;
---------------------------------------------------------------------
-- 10220 rows
---------------------------------------------------------------------
-- Table: users
-- DROP TABLE users;
CREATE TABLE users
(
userid integer NOT NULL,
firstname character varying(50) NOT NULL,
lastname character varying(50),
birthdate date,
professionalemailid character varying(100) NOT NULL,
languages character varying(100),
personalemailid character varying(100),
countryid integer NOT NULL,
major integer,
CONSTRAINT users_pkey PRIMARY KEY (userid),
CONSTRAINT fk_country_idx FOREIGN KEY (countryid)
REFERENCES country (countryid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE SET NULL
)
WITH (
OIDS=FALSE
);
ALTER TABLE users
OWNER TO postgres;
-- Index: fki_country_idx
-- DROP INDEX fki_country_idx;
CREATE INDEX fki_country_idx
ON users
USING btree
(countryid);
----------------------------------------------------------------
-- 299999 rows
----------------------------------------------------------------