Skip to content

Commit 521cea4

Browse files
remove the Allen CCF example from Lookup Tables.
1 parent 5b1f2a4 commit 521cea4

File tree

4 files changed

+122
-296
lines changed

4 files changed

+122
-296
lines changed

book/20-concepts/00-databases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Modern databases typically separate data management from data use through distin
8181
### Common Architectures
8282

8383
**Server-Client Architecture** (most common): A database server program manages all data operations, while client programs (your scripts, applications, notebooks) connect to request data or submit changes. The server enforces all rules and access permissions consistently for every client. This is like a library where the librarian (server) manages the books and enforces checkout policies, while patrons (clients) request materials.
84-
The two most popular open-source relational database systems: MySQL and Postgres implement a server-client architecture.
84+
The two most popular open-source relational database systems: MySQL and PostgreSQL implement a server-client architecture.
8585

8686
**Embedded Databases**: The database engine runs within your application itself—no separate server. This works for single-user applications like mobile apps or desktop software, but doesn't support multiple users accessing shared data simultaneously.
8787
SQLite is a common embedded database @10.14778/3554821.3554842.

book/20-concepts/03-relational-practice.md

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ erDiagram
6767
6868
RESEARCHER {
6969
int researcher_id PK
70-
string name
70+
string researcher_name
7171
string email
7272
string lab_role
7373
}
@@ -89,16 +89,17 @@ erDiagram
8989
}
9090
9191
RECORDING {
92+
int experiment_id PK, FK
9293
int recording_id PK
93-
int experiment_id FK
9494
datetime recording_time
9595
string file_path
9696
string recording_quality
9797
}
9898
9999
NEURAL_UNIT {
100+
int experiment_id PK, FK
101+
int recording_id PK, FK
100102
int unit_id PK
101-
int recording_id FK
102103
float spike_rate
103104
float receptive_field_size
104105
}
@@ -118,55 +119,57 @@ The ER diagram translates almost directly to SQL table definitions:
118119

119120
```sql
120121
CREATE TABLE Researcher (
121-
researcher_id INT PRIMARY KEY AUTO_INCREMENT,
122+
researcher_id INT,
122123
name VARCHAR(100) NOT NULL,
123124
email VARCHAR(100) UNIQUE,
124-
lab_role VARCHAR(50)
125+
lab_role VARCHAR(50),
126+
PRIMARY KEY(researcher_id)
125127
);
126128

127129
CREATE TABLE AnimalSubject (
128-
subject_id INT PRIMARY KEY AUTO_INCREMENT,
130+
subject_id INT PRIMARY KEY,
129131
species VARCHAR(50) NOT NULL,
130132
date_of_birth DATE,
131133
sex ENUM('M', 'F', 'Unknown')
132134
);
133135

134136
CREATE TABLE Experiment (
135-
experiment_id INT PRIMARY KEY AUTO_INCREMENT,
137+
experiment_id INT,
136138
researcher_id INT NOT NULL,
137139
subject_id INT NOT NULL,
138140
experiment_date DATE NOT NULL,
139141
description TEXT,
140142
protocol VARCHAR(100),
143+
PRIMARY KEY (experiment_id),
141144
FOREIGN KEY (researcher_id) REFERENCES Researcher(researcher_id),
142145
FOREIGN KEY (subject_id) REFERENCES AnimalSubject(subject_id)
143146
);
144147

145148
CREATE TABLE Recording (
146-
recording_id INT PRIMARY KEY AUTO_INCREMENT,
147149
experiment_id INT NOT NULL,
150+
recording_id INT NOT NULL,
148151
recording_time DATETIME NOT NULL,
149152
file_path VARCHAR(255) NOT NULL,
150153
recording_quality ENUM('excellent', 'good', 'fair', 'poor'),
154+
PRIMARY KEY (experiment_id, recording_id),
151155
FOREIGN KEY (experiment_id) REFERENCES Experiment(experiment_id)
152-
ON DELETE CASCADE
153156
);
154157

155158
CREATE TABLE NeuralUnit (
156-
unit_id INT PRIMARY KEY AUTO_INCREMENT,
159+
experiment_id INT NOT NULL,
157160
recording_id INT NOT NULL,
158-
spike_rate FLOAT,
159-
receptive_field_size FLOAT,
160-
FOREIGN KEY (recording_id) REFERENCES Recording(recording_id)
161-
ON DELETE CASCADE
161+
unit_id INT NOT NULL,
162+
spike_rate FLOAT NOT NULL,
163+
receptive_field_size FLOAT NOT NULL,
164+
PRIMARY KEY (experiment_id, recording_id, unit_id),
165+
FOREIGN KEY (experiment_id, recording_id) REFERENCES Recording(experiment_id, recording_id)
162166
);
163167
```
164168

165169
Note the key features:
166170
- **PRIMARY KEY**: Ensures each row has a unique identifier
167171
- **FOREIGN KEY**: Enforces referential integrity—you can't reference a non-existent entity
168172
- **NOT NULL**: Requires certain attributes to have values
169-
- **ON DELETE CASCADE**: Automatically removes dependent records when parent is deleted
170173
- **Data types**: Constrain what values can be stored (INT, VARCHAR, DATE, etc.)
171174

172175
### Populating with Sample Data
@@ -175,31 +178,31 @@ Let's add some sample data to see the database in action:
175178

176179
```sql
177180
-- Add researchers
178-
INSERT INTO Researcher (name, email, lab_role) VALUES
179-
('Dr. Sarah Chen', '[email protected]', 'Principal Investigator'),
180-
('Alex Martinez', '[email protected]', 'Postdoc'),
181-
('Jamie Park', '[email protected]', 'Graduate Student');
181+
INSERT INTO Researcher (researcher_id, name, email, lab_role) VALUES
182+
(1, 'Dr. Sarah Chen', '[email protected]', 'Principal Investigator'),
183+
(2, 'Alex Martinez', '[email protected]', 'Postdoc'),
184+
(3, 'Jamie Park', '[email protected]', 'Graduate Student');
182185

183186
-- Add animal subjects
184-
INSERT INTO AnimalSubject (species, date_of_birth, sex) VALUES
187+
INSERT INTO AnimalSubject (subject_id, aspecies, date_of_birth, sex) VALUES
185188
('Mouse', '2024-01-15', 'M'),
186189
('Mouse', '2024-01-20', 'F'),
187190
('Mouse', '2024-02-03', 'M');
188191

189192
-- Add an experiment
190-
INSERT INTO Experiment (researcher_id, subject_id, experiment_date, description, protocol) VALUES
191-
(2, 1, '2024-08-15', 'Visual cortex recording during grating stimuli', 'Protocol-V1-001');
193+
INSERT INTO Experiment (experiment_id, researcher_id, subject_id, experiment_date, description, protocol) VALUES
194+
(1, 2, 1, '2024-08-15', 'Visual cortex recording during grating stimuli', 'Protocol-V1-001');
192195

193196
-- Add recordings from that experiment
194-
INSERT INTO Recording (experiment_id, recording_time, file_path, recording_quality) VALUES
195-
(1, '2024-08-15 10:30:00', '/data/2024/08/15/rec001.dat', 'excellent'),
196-
(1, '2024-08-15 11:45:00', '/data/2024/08/15/rec002.dat', 'good');
197+
INSERT INTO Recording (experiment_id, recording_id, recording_time, file_path, recording_quality) VALUES
198+
(1, 1, '2024-08-15 10:30:00', '/data/2024/08/15/rec001.dat', 'excellent'),
199+
(1, 2, '2024-08-15 11:45:00', '/data/2024/08/15/rec002.dat', 'good');
197200

198201
-- Add neural units identified in first recording
199-
INSERT INTO NeuralUnit (recording_id, spike_rate, receptive_field_size) VALUES
200-
(1, 15.3, 2.5),
201-
(1, 8.7, 3.1),
202-
(1, 22.4, 1.8);
202+
INSERT INTO NeuralUnit (experiment_id, recording_id, unit_id, spike_rate, receptive_field_size) VALUES
203+
(1, 1, 1, 15.3, 2.5),
204+
(1, 1, 2, 8.7, 3.1),
205+
(1, 1, 3, 22.4, 1.8);
203206
```
204207

205208
## Common Database Operations

0 commit comments

Comments
 (0)