forked from bswaby/Touchpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOC_SQLDocumentation.html
More file actions
5051 lines (4705 loc) · 155 KB
/
DOC_SQLDocumentation.html
File metadata and controls
5051 lines (4705 loc) · 155 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
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Swaby's Touchpoint SQL Database Reference Guide</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
line-height: 1.6;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: #f8fafc;
color: #1a202c;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 40px;
border-radius: 10px;
margin-bottom: 30px;
text-align: center;
}
.header h1 {
margin: 0 0 15px 0;
font-size: 2.8em;
font-weight: 700;
}
.header .subtitle {
font-size: 1.3em;
opacity: 0.95;
margin: 0 0 20px 0;
}
.header .version {
font-size: 1em;
opacity: 0.9;
background: rgba(255,255,255,0.2);
display: inline-block;
padding: 5px 15px;
border-radius: 20px;
}
.intro-section {
background: white;
padding: 30px;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.warning {
background: #fed7e2;
border: 2px solid #e53e3e;
padding: 15px;
border-radius: 8px;
margin: 20px 0;
}
.info {
background: #bee3f8;
border: 2px solid #3182ce;
padding: 15px;
border-radius: 8px;
margin: 20px 0;
}
.success {
background: #c6f6d5;
border: 2px solid #38a169;
padding: 15px;
border-radius: 8px;
margin: 20px 0;
}
.toc {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
}
.toc h2 {
margin-top: 0;
color: #2d3748;
border-bottom: 3px solid #4299e1;
padding-bottom: 10px;
font-size: 2em;
}
.toc h3 {
color: #4299e1;
margin-top: 25px;
margin-bottom: 10px;
font-size: 1.3em;
}
.toc ul {
list-style: none;
padding-left: 0;
}
.toc li {
margin: 8px 0;
padding-left: 20px;
position: relative;
}
.toc li:before {
content: "→";
position: absolute;
left: 0;
color: #4299e1;
}
.toc a {
color: #4299e1;
text-decoration: none;
font-weight: 500;
transition: all 0.2s;
}
.toc a:hover {
color: #2c5282;
text-decoration: underline;
}
.section {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
}
h1, h2, h3, h4 {
color: #2d3748;
}
h2 {
border-bottom: 3px solid #4299e1;
padding-bottom: 10px;
margin-top: 0;
font-size: 1.8em;
}
h3 {
color: #4299e1;
margin-top: 25px;
font-size: 1.4em;
}
h4 {
color: #4a5568;
margin-top: 20px;
font-size: 1.2em;
}
pre {
background: #2d3748 !important;
color: #e2e8f0 !important;
padding: 20px !important;
border-radius: 8px !important;
overflow-x: auto !important;
font-family: 'SF Mono', Monaco, 'Inconsolata', 'Roboto Mono', Consolas, monospace !important;
line-height: 1.5 !important;
font-size: 0.95em !important;
position: relative;
margin: 15px 0 !important;
}
pre code {
background: transparent !important;
color: #e2e8f0 !important;
padding: 0 !important;
font-size: inherit !important;
}
:not(pre) > code {
background: #edf2f7 !important;
padding: 3px 6px !important;
border-radius: 4px !important;
font-family: 'SF Mono', Monaco, monospace !important;
color: #e53e3e !important;
font-size: 0.9em !important;
}
.critical {
background: #fed7e2;
border-left: 5px solid #e53e3e;
padding: 15px;
margin: 20px 0;
border-radius: 0 8px 8px 0;
}
.highlight {
background: #fef5e7;
border-left: 5px solid #ed8936;
padding: 15px;
margin: 20px 0;
border-radius: 0 8px 8px 0;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
background: white;
}
th, td {
border: 1px solid #e2e8f0;
padding: 12px;
text-align: left;
}
th {
background: #edf2f7;
font-weight: 600;
color: #2d3748;
}
tr:nth-child(even) {
background: #f7fafc;
}
.back-to-top {
position: fixed;
bottom: 30px;
right: 30px;
background: #4299e1;
color: white;
padding: 12px 20px;
border-radius: 50px;
text-decoration: none;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: all 0.3s;
font-weight: 600;
z-index: 1000;
}
.back-to-top:hover {
background: #3182ce;
transform: translateY(-2px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
.copy-button {
position: absolute;
top: 10px;
right: 10px;
background: #4299e1;
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
font-weight: 500;
transition: all 0.2s;
}
.copy-button:hover {
background: #3182ce;
}
.field-table {
font-size: 0.95em;
}
.field-table th:first-child {
width: 25%;
}
.field-table th:nth-child(2) {
width: 15%;
}
.field-table code {
font-size: 0.9em !important;
}
.badge {
display: inline-block;
padding: 3px 8px;
border-radius: 4px;
font-size: 0.85em;
font-weight: 600;
margin-left: 8px;
}
.badge-critical {
background: #fed7e2;
color: #c53030;
}
.badge-new {
background: #c6f6d5;
color: #22543d;
}
.badge-performance {
background: #fef5e7;
color: #c05621;
}
@media (max-width: 768px) {
body {
padding: 10px;
}
.header {
padding: 20px;
}
.header h1 {
font-size: 2em;
}
.section, .toc {
padding: 20px;
}
pre {
padding: 15px !important;
font-size: 0.85em !important;
}
}
@media print {
body { background: white; }
.section { box-shadow: none; border: 1px solid #e2e8f0; }
.back-to-top { display: none; }
.copy-button { display: none; }
.toc { page-break-after: always; }
}
</style>
</head>
<body>
<div class="header">
<h1>Swaby's TouchPoint SQL Database Reference</h1>
<p class="subtitle">My Personal Guide to the TouchPoint's Church Management Database</p>
<div class="version">Version: The smothered, covered, chunked, and diced version.</div>
</div>
<div class="intro-section">
<h2>📚 About This Guide</h2>
<p>I could keep up with all the tables and relationships, so started creating my own documented version of the structure to take at least a small bite out of TouchPoint's extensive SQL database structure.</p>
<div class="info">
<h3>👥 Who This Guide Is For</h3>
<ul>
<li><strong>Church Database Administrators</strong> - Managing and querying church data</li>
<li><strong>Report Writers</strong> - Creating custom reports and analytics</li>
<li><strong>Developers</strong> - Building integrations and custom solutions</li>
<li><strong>Church Leadership</strong> - Understanding data capabilities</li>
</ul>
</div>
<div class="warning">
<h3>⚠️ Critical: TouchPoint SQL is READ-ONLY</h3>
<p><strong>The SQL interface provides READ-ONLY access to the database.</strong> You cannot INSERT, UPDATE, or DELETE records through SQL. All data modifications must be done through:</p>
<ul>
<li>✅ TouchPoint's web interface</li>
<li>✅ TouchPoint's Python scripting system</li>
<li>✅ TouchPoint's API endpoints</li>
<li>✅ TouchPoint's mobile app</li>
</ul>
<p>This guide focuses on SELECT queries for reporting, analysis, and data extraction.</p>
</div>
<div class="success">
<h3>✨ What's New in this Documentation</h3>
<ul>
<li>📊 Complete coverage of all 378 tables and 3,364 columns</li>
<li>🚀 Performance guidelines for tables with millions of records</li>
<li>🔧 Advanced systems documentation (Tags, Email, Engagement)</li>
<li>📝 Registration and Check-in system details</li>
<li>🎛️ Custom field system (Extra Values) documentation</li>
<li>📱 Mobile app integration fields</li>
<li>✅ Corrected OrganizationStatusId values and other critical fixes</li>
</ul>
</div>
</div>
<div class="toc">
<h2>📖 Table of Contents</h2>
<h3>🚀 Getting Started</h3>
<ul>
<li><a href="#database-overview">Database Overview & Architecture</a></li>
<li><a href="#critical-rules">Critical Business Rules - READ THIS FIRST</a></li>
<li><a href="#performance-guidelines">Performance Guidelines & Large Table Warnings</a></li>
<li><a href="#common-queries">Most Common Queries (Quick Reference)</a></li>
</ul>
<h3>👥 People & Families</h3>
<ul>
<li><a href="#people-table">People Table - Complete Reference</a></li>
<li><a href="#family-structure">Family Relationships & Household Management</a></li>
<li><a href="#contact-permissions">Contact Information & Communication Permissions</a></li>
<li><a href="#membership-workflow">Church Membership Status & Workflow</a></li>
</ul>
<h3>🏛️ Organizations & Groups</h3>
<ul>
<li><a href="#organizations-table">Organizations Table (Involvements)</a></li>
<li><a href="#organization-members">Organization Membership & Roles</a></li>
<li><a href="#program-hierarchy">Program → Division → Organization Structure</a></li>
<li><a href="#organization-types">Organization Types & Classification</a></li>
</ul>
<h3>📅 Attendance & Meetings</h3>
<ul>
<li><a href="#attend-table">Attend Table - The AttendanceFlag Rule</a></li>
<li><a href="#meetings-table">Meetings & Scheduling</a></li>
<li><a href="#attendance-types">Attendance Types & Classifications</a></li>
<li><a href="#attendance-analytics">Attendance Analytics & Patterns</a></li>
</ul>
<h3>💰 Financial & Contributions</h3>
<ul>
<li><a href="#contribution-table">Contribution Table - The TypeId≠99 Rule</a></li>
<li><a href="#contribution-funds">Funds & Designations</a></li>
<li><a href="#bundle-system">Bundle & Batch Processing</a></li>
<li><a href="#transaction-system">Transactions & Outstanding Balances</a></li>
</ul>
<h3>📝 Events & Registration</h3>
<ul>
<li><a href="#registration-system">Registration System Architecture</a></li>
<li><a href="#registration-questions">Custom Forms & Questions</a></li>
<li><a href="#registration-fees">Registration Fees & Payments</a></li>
<li><a href="#event-management">Event Management & Scheduling</a></li>
</ul>
<h3>🎫 Check-In System</h3>
<ul>
<li><a href="#checkin-overview">Check-In System Overview</a></li>
<li><a href="#checkin-activity">Check-In Activity & Times</a></li>
<li><a href="#checkin-configuration">Check-In Configuration & Settings</a></li>
<li><a href="#barcode-system">Barcode & Security Labels</a></li>
</ul>
<h3>📧 Communication Systems</h3>
<ul>
<li><a href="#email-system">Email Marketing System (3.9M+ records)</a></li>
<li><a href="#sms-system">SMS/Text Messaging System</a></li>
<li><a href="#task-system">Tasks & Ministry Communication</a></li>
<li><a href="#notification-preferences">Notification Preferences & Opt-outs</a></li>
</ul>
<h3>📊 Advanced Analytics</h3>
<ul>
<li><a href="#engagement-scoring">Engagement Scoring System (1.4M+ records)</a></li>
<li><a href="#tag-system">Tag System (138M+ records)</a></li>
<li><a href="#activity-logging">Activity Logging & Audit Trail</a></li>
<li><a href="#change-tracking">Change Tracking & History</a></li>
</ul>
<h3>🎛️ Customization Systems</h3>
<ul>
<li><a href="#extra-values">Extra Value Tables (Custom Fields)</a></li>
<li><a href="#lookup-tables">Lookup Tables Reference (67+ tables)</a></li>
<li><a href="#settings-framework">Settings & Configuration Framework</a></li>
<li><a href="#content-management">Content & Template Management</a></li>
</ul>
<h3>📱 Mobile & Integration</h3>
<ul>
<li><a href="#mobile-app">Mobile App Configuration</a></li>
<li><a href="#picture-system">Picture & Media Management</a></li>
<li><a href="#search-optimization">Search Optimization System</a></li>
<li><a href="#api-integration">API Integration Points</a></li>
</ul>
<h3>🔐 Security & Administration</h3>
<ul>
<li><a href="#users-roles">Users, Roles & Permissions</a></li>
<li><a href="#security-settings">Security Settings & Access Control</a></li>
<li><a href="#data-privacy">Data Privacy & Protection</a></li>
</ul>
<h3>📈 Reporting & Analytics</h3>
<ul>
<li><a href="#common-reports">Common Report Patterns</a></li>
<li><a href="#dashboard-queries">Dashboard & KPI Queries</a></li>
<li><a href="#growth-analytics">Growth & Trend Analytics</a></li>
<li><a href="#financial-reports">Financial Reporting Queries</a></li>
</ul>
<h3>🔧 Reference & Troubleshooting</h3>
<ul>
<li><a href="#field-reference">Complete Field Reference</a></li>
<li><a href="#relationship-diagram">Table Relationship Diagrams</a></li>
<li><a href="#common-issues">Common Issues & Solutions</a></li>
<li><a href="#best-practices">Best Practices & Tips</a></li>
</ul>
</div>
<div id="database-overview" class="section">
<h2>📊 Database Overview & Architecture</h2>
<p>TouchPoint is an enterprise-level church management system with one of the most comprehensive databases in the church software industry. Understanding its scale and architecture is crucial for effective use.</p>
<h3>🏗️ Database Scale</h3>
<table>
<tr>
<th>Metric</th>
<th>Count</th>
<th>Description</th>
</tr>
<tr>
<td><strong>Total Tables</strong></td>
<td>378</td>
<td>Complete system coverage from people to analytics</td>
</tr>
<tr>
<td><strong>Total Columns</strong></td>
<td>3,364</td>
<td>Extensive data points for comprehensive tracking</td>
</tr>
<tr>
<td><strong>Foreign Keys</strong></td>
<td>452</td>
<td>Complex relationships ensuring data integrity</td>
</tr>
<tr>
<td><strong>Lookup Tables</strong></td>
<td>67</td>
<td>Business logic and validation rules</td>
</tr>
<tr>
<td><strong>Extra Value Tables</strong></td>
<td>17</td>
<td>Unlimited custom field capabilities</td>
</tr>
<tr>
<td><strong>Stored Procedures</strong></td>
<td>495</td>
<td>Complex operations and reporting</td>
</tr>
</table>
<h3>📈 Production Data Volumes</h3>
<div class="highlight">
<p><strong>Real-world production databases can contain massive data volumes:</strong></p>
<table>
<tr>
<th>Table</th>
<th>Record Count</th>
<th>Purpose</th>
<th>Performance Impact</th>
</tr>
<tr>
<td><code>TagPerson</code></td>
<td>138M+</td>
<td>Flexible categorization</td>
<td><span class="badge badge-critical">EXTREME</span></td>
</tr>
<tr>
<td><code>EmailResponses</code></td>
<td>3.9M+</td>
<td>Email engagement tracking</td>
<td><span class="badge badge-critical">HIGH</span></td>
</tr>
<tr>
<td><code>EmailQueueTo</code></td>
<td>3.8M+</td>
<td>Email recipients</td>
<td><span class="badge badge-critical">HIGH</span></td>
</tr>
<tr>
<td><code>ActivityLog</code></td>
<td>3.4M+</td>
<td>Audit trail</td>
<td><span class="badge badge-critical">HIGH</span></td>
</tr>
<tr>
<td><code>PeopleSearchTokens</code></td>
<td>1.7M+</td>
<td>Search optimization</td>
<td><span class="badge badge-performance">MEDIUM</span></td>
</tr>
<tr>
<td><code>EngagementScoreTag</code></td>
<td>1.4M+</td>
<td>Activity scoring</td>
<td><span class="badge badge-performance">MEDIUM</span></td>
</tr>
<tr>
<td><code>Attend</code></td>
<td>1.2M+</td>
<td>Attendance records</td>
<td><span class="badge badge-performance">MEDIUM</span></td>
</tr>
<tr>
<td><code>Contribution</code></td>
<td>673K+</td>
<td>Financial giving</td>
<td>LOW</td>
</tr>
</table>
</div>
<h3>🏛️ Core System Architecture</h3>
<pre><code>-- Core Entity Relationships
People (PeopleId)
├── FamilyId → Groups family members
├── SpouseId → Direct spouse link
└── OrganizationMembers → Group participation
└── Organizations (OrganizationId)
├── Meetings → Scheduled events
└── Attend → Attendance records
People (PeopleId)
├── Contribution → Financial giving
│ └── ContributionFund → Designated funds
├── TaskNote → Tasks and notes
└── Registration → Event signups
└── RegPeople → Participants
└── RegAnswer → Form responses</code></pre>
</div>
<div id="critical-rules" class="section">
<h2>🚨 Critical Business Rules - READ THIS FIRST</h2>
<div class="critical">
<h3>⚠️ Rule #1: ALWAYS Use TOP Clause for Exploration</h3>
<p>TouchPoint databases can contain millions of records. <strong>Never run unlimited queries without the TOP clause</strong> during exploration or testing.</p>
<pre><code>-- ✅ CORRECT: Always start with TOP
SELECT TOP 100 * FROM People WHERE IsDeceased = 0 AND ArchivedFlag = 0
-- ❌ WRONG: Never run unlimited on large tables
SELECT * FROM TagPerson -- This table has 138M+ records!</code></pre>
</div>
<div class="critical">
<h3>⚠️ Rule #2: Mandatory Filters for Every Query</h3>
<pre><code>-- 🚨 FILTER #1: Active People Only
WHERE p.IsDeceased = 0 AND p.ArchivedFlag = 0
-- 🚨 FILTER #2: Actual Attendance (not absences)
WHERE a.AttendanceFlag = 1 -- 1 = present, 0 = absent
-- 🚨 FILTER #3: Real Donations (not event fees)
WHERE c.ContributionTypeId != 99 -- 99 = event registration fee
-- 🚨 FILTER #4: Active Organizations
WHERE o.OrganizationStatusId = 30 -- 30 = Active
-- 🚨 FILTER #5: Current Members Only
WHERE om.InactiveDate IS NULL
-- 🚨 FILTER #6: Completed Meetings
WHERE m.DidNotMeet = 0</code></pre>
</div>
<div class="highlight">
<h3>📋 Communication Compliance Rules</h3>
<pre><code>-- Always check permissions before communication
WHERE p.DoNotMailFlag = 0 -- Can send mail
WHERE p.DoNotCallFlag = 0 -- Can make calls
WHERE p.DoNotVisitFlag = 0 -- Can visit
WHERE p.ReceiveSMS = 1 -- Can send texts
WHERE p.SendEmailAddress1 = 1 -- Can email primary
WHERE p.SendEmailAddress2 = 1 -- Can email secondary</code></pre>
</div>
<div class="warning">
<h3>⚠️ Data Quality Filters</h3>
<pre><code>-- Ensure good data quality
WHERE p.PrimaryBadAddrFlag = 0 -- Valid addresses only
WHERE p.CellPhoneIsValid = 1 -- Valid phone numbers
WHERE p.EmailAddress IS NOT NULL AND p.EmailAddress != ''</code></pre>
</div>
</div>
<div id="performance-guidelines" class="section">
<h2>⚡ Performance Guidelines & Large Table Warnings</h2>
<h3>🎯 TOP Clause Usage Guidelines</h3>
<table>
<tr>
<th>Purpose</th>
<th>TOP Value</th>
<th>Use Case</th>
</tr>
<tr>
<td>Initial Exploration</td>
<td><code>TOP 100</code></td>
<td>Testing queries, understanding data structure</td>
</tr>
<tr>
<td>Sample Review</td>
<td><code>TOP 500</code></td>
<td>Reviewing data patterns, quality checks</td>
</tr>
<tr>
<td>Larger Analysis</td>
<td><code>TOP 1000</code></td>
<td>Statistical sampling, trend analysis</td>
</tr>
<tr>
<td>Comprehensive Sample</td>
<td><code>TOP 5000</code></td>
<td>Large samples (use with caution)</td>
</tr>
<tr>
<td>Full Dataset</td>
<td>No TOP</td>
<td>ONLY for final production reports after testing</td>
</tr>
</table>
<h3>🚨 High-Volume Table Requirements</h3>
<div class="critical">
<p><strong>These tables REQUIRE date filters and TOP clauses:</strong></p>
<pre><code>-- TagPerson (138M+ records) - EXTREME CAUTION
SELECT TOP 100 * FROM TagPerson tp
WHERE tp.DateCreated >= DATEADD(day, -30, GETDATE())
-- EmailResponses (3.9M+ records)
SELECT TOP 100 * FROM EmailResponses er
WHERE er.Dt >= DATEADD(week, -1, GETDATE())
-- ActivityLog (3.4M+ records)
SELECT TOP 100 * FROM ActivityLog al
WHERE al.ActivityDate >= DATEADD(day, -7, GETDATE())
-- EngagementScoreTag (1.4M+ records)
SELECT TOP 100 * FROM EngagementScoreTag est
JOIN EngagementScore es ON est.EngagementScoreId = es.Id
WHERE es.WeekDate >= DATEADD(month, -3, GETDATE())
-- EmailQueueTo (3.8M+ records)
SELECT TOP 100 * FROM EmailQueueTo eqt
JOIN EmailQueue eq ON eqt.Id = eq.Id
WHERE eq.Sent >= DATEADD(month, -1, GETDATE())</code></pre>
</div>
<h3>✅ Safe Query Development Process</h3>
<pre><code>-- STEP 1: Start with minimal data
SELECT TOP 10 *
FROM YourTable
WHERE DateField >= DATEADD(day, -1, GETDATE())
-- STEP 2: Verify query logic with small sample
SELECT TOP 100
SpecificColumns,
YouNeed
FROM YourTable
WHERE DateField >= DATEADD(week, -1, GETDATE())
AND OtherFilters = 'Applied'
-- STEP 3: Expand sample if needed
SELECT TOP 1000
-- your final column list
FROM YourTable
WHERE -- all your filters
ORDER BY -- your sort
-- STEP 4: Remove TOP only for production reports
-- after confirming performance is acceptable</code></pre>
</div>
<div id="common-queries" class="section">
<h2>🎯 Most Common Queries (Quick Reference)</h2>
<h3>👥 Active Church Members</h3>
<pre><code>SELECT TOP 1000
p.PeopleId,
p.Name,
p.EmailAddress,
p.CellPhone,
ms.Description as MemberStatus,
DATEDIFF(year, p.BDate, GETDATE()) as Age,
c.Description as Campus
FROM People p
JOIN lookup.MemberStatus ms ON p.MemberStatusId = ms.Id
LEFT JOIN lookup.Campus c ON p.CampusId = c.Id
WHERE p.IsDeceased = 0
AND p.ArchivedFlag = 0
AND p.MemberStatusId = 10 -- Members only
ORDER BY p.Name</code></pre>
<h3>📅 Recent Attendance</h3>
<pre><code>SELECT TOP 500
p.Name,
o.OrganizationName,
m.MeetingDate,
at.Description as AttendanceType
FROM Attend a
JOIN People p ON a.PeopleId = p.PeopleId
JOIN Organizations o ON a.OrganizationId = o.OrganizationId
JOIN Meetings m ON a.MeetingId = m.MeetingId
JOIN lookup.AttendType at ON a.AttendanceTypeId = at.Id
WHERE a.AttendanceFlag = 1 -- Critical: actual attendance
AND m.MeetingDate >= DATEADD(week, -1, GETDATE())
AND m.DidNotMeet = 0
AND p.IsDeceased = 0 AND p.ArchivedFlag = 0
ORDER BY m.MeetingDate DESC, o.OrganizationName, p.Name</code></pre>
<h3>💰 Recent Giving</h3>
<pre><code>SELECT TOP 500
p.Name,
c.ContributionDate,
c.ContributionAmount,
cf.FundName,
c.CheckNo
FROM Contribution c
JOIN People p ON c.PeopleId = p.PeopleId
JOIN ContributionFund cf ON c.FundId = cf.FundId
WHERE c.ContributionTypeId != 99 -- Exclude event fees
AND c.ContributionDate >= DATEADD(month, -1, GETDATE())
AND p.IsDeceased = 0 AND p.ArchivedFlag = 0
ORDER BY c.ContributionDate DESC, c.ContributionAmount DESC</code></pre>
<h3>🆕 First-Time Visitors</h3>
<pre><code>-- Recent first-time visitors for follow-up
WITH FirstVisit AS (
SELECT
p.PeopleId,
MIN(a.MeetingDate) as FirstVisitDate
FROM Attend a
JOIN People p ON a.PeopleId = p.PeopleId
WHERE a.AttendanceFlag = 1
AND a.AttendanceTypeId IN (40, 50) -- New Guest, Recent Guest
GROUP BY p.PeopleId
)
SELECT TOP 100
p.Name,
p.EmailAddress,
p.CellPhone,
fv.FirstVisitDate,
DATEDIFF(day, fv.FirstVisitDate, GETDATE()) as DaysSinceVisit
FROM FirstVisit fv
JOIN People p ON fv.PeopleId = p.PeopleId
WHERE fv.FirstVisitDate >= DATEADD(week, -2, GETDATE())
AND p.DoNotCallFlag = 0
AND p.DoNotVisitFlag = 0
AND p.IsDeceased = 0
AND p.ArchivedFlag = 0
ORDER BY fv.FirstVisitDate DESC</code></pre>
<h3>📊 Organization Summary</h3>
<pre><code>SELECT TOP 100
o.OrganizationName,
o.Location,
leader.Name as Leader,
o.MemberCount,
o.Limit as Capacity,
CASE
WHEN o.Limit > 0 THEN
CAST(o.MemberCount as float) / o.Limit * 100
ELSE 0
END as PercentFull,
o.FirstMeetingDate,
o.LastMeetingDate
FROM Organizations o
LEFT JOIN People leader ON o.LeaderId = leader.PeopleId
WHERE o.OrganizationStatusId = 30 -- Active
ORDER BY o.MemberCount DESC</code></pre>
</div>
<div id="people-table" class="section">
<h2>👥 People Table - Complete Reference</h2>
<p><strong>Purpose:</strong> Central repository for all person and family data<br>
<strong>Primary Key:</strong> <code>PeopleId</code><br>
<strong>Scale:</strong> 136 columns with 23 foreign key relationships<br>
<strong>Critical Rule:</strong> Always filter <code>WHERE IsDeceased = 0 AND ArchivedFlag = 0</code></p>
<h3>Core Identity Fields</h3>
<table class="field-table">
<tr>
<th>Field</th>
<th>Type</th>
<th>Description</th>
<th>Usage</th>
</tr>
<tr>
<td><code>PeopleExtra</code></td>
<td>Mixed</td>
<td>Person-specific custom fields</td>
</tr>
<tr>
<td><code>ExtraValueBit</code></td>
<td>Boolean</td>
<td>Yes/No fields</td>
</tr>
<tr>
<td><code>ExtraValueDate</code></td>
<td>DateTime</td>
<td>Date fields</td>
</tr>
<tr>
<td><code>ExtraValueInt</code></td>
<td>Integer</td>
<td>Number fields</td>
</tr>
<tr>
<td><code>ExtraValueText</code></td>
<td>Text</td>
<td>Text fields</td>
</tr>
<tr>
<td><code>ExtraValueCode</code></td>
<td>Code</td>
<td>Dropdown/lookup fields</td>
</tr>
<tr>
<td><code>OrgExtra</code></td>
<td>Mixed</td>
<td>Organization custom fields</td>
</tr>
<tr>
<td><code>MeetingExtra</code></td>
<td>Mixed</td>
<td>Meeting custom fields</td>
</tr>
<tr>
<td><code>ContributionExtra</code></td>
<td>Mixed</td>
<td>Contribution custom fields</td>
</tr>
</table>
<h3>Discovering Custom Fields</h3>
<pre><code>-- Find what custom fields your church uses
SELECT TOP 500
'PeopleExtra' as TableType,
Field,
COUNT(*) as RecordCount,
COUNT(DISTINCT PeopleId) as PeopleWithValue
FROM PeopleExtra
GROUP BY Field
ORDER BY COUNT(*) DESC
-- Example: Using a custom field
SELECT
p.Name,
pev.Field,
pev.Data as Value
FROM People p
JOIN PeopleExtra pev ON p.PeopleId = pev.PeopleId
WHERE pev.Field = 'MembershipCovenant' -- Church-specific field
AND p.IsDeceased = 0 AND p.ArchivedFlag = 0
ORDER BY p.Name</code></pre>
<h3>Custom Field Analysis</h3>
<pre><code>-- Analyze custom field usage patterns
WITH CustomFieldStats AS (
SELECT
Field,
COUNT(*) as Uses,
COUNT(DISTINCT PeopleId) as UniquePeople,
MIN(CAST(Data as datetime)) as EarliestDate,
MAX(CAST(Data as datetime)) as LatestDate
FROM PeopleExtra
WHERE Field LIKE '%Date%' -- Date-type fields
AND ISDATE(Data) = 1
GROUP BY Field
)
SELECT
Field,
Uses,
UniquePeople,
EarliestDate,
LatestDate,
DATEDIFF(day, EarliestDate, LatestDate) as DateRange
FROM CustomFieldStats
ORDER BY Uses DESC</code></pre>
</div>
<div id="lookup-tables" class="section">
<h2>📚 Lookup Tables Reference</h2>
<p>TouchPoint includes 67+ lookup tables that provide business logic, validation rules, and categorization throughout the system.</p>
<h3>Critical Lookup Tables</h3>
<h4>lookup.MemberStatus <span class="badge badge-critical">Most Important</span></h4>
<table>
<tr>
<th>Id</th>
<th>Description</th>
<th>Usage</th>
</tr>
<tr>
<td>10</td>
<td>Member</td>
<td>Full church members - voting, leadership eligible</td>
</tr>