Example Schema

The example schema below contains data for a university enrollment system. Information about students, departments, courses, etc. are organized in multiple tables.

Warning

Empty primary keys, such as in the CurrentTerm table, are not yet supported by DataJoint. This feature will become available in a future release. See Issue #127 for more information.

File +university/Student.m

%{
  student_id      : int unsigned # university ID
  ---
  first_name      : varchar(40)
  last_name       : varchar(40)
  sex             : enum('F', 'M', 'U')
  date_of_birth   : date
  home_address    : varchar(200) # street address
  home_city       : varchar(30)
  home_state      : char(2) # two-letter abbreviation
  home_zipcode    : char(10)
  home_phone      : varchar(14)
%}
classdef Student < dj.Manual
end

File +university/Department.m

%{
  dept         : char(6) # abbreviated department name, e.g. BIOL
  ---
  dept_name    : varchar(200) # full department name
  dept_address : varchar(200) # mailing address
  dept_phone   : varchar(14)
%}
classdef Department < dj.Manual
end

File +university/StudentMajor.m

%{
  -> university.Student
  ---
  -> university.Department
  declare_date :  date # when student declared her major
%}
classdef StudentMajor < dj.Manual
end

File +university/Course.m

%{
  -> university.Department
  course      : int unsigned # course number, e.g. 1010
  ---
  course_name : varchar(200) # e.g. "Cell Biology"
  credits     : decimal(3,1) # number of credits earned by completing the course
%}
classdef Course < dj.Manual
end

File +university/Term.m

%{
  term_year : year
  term      : enum('Spring', 'Summer', 'Fall')
%}
classdef Term < dj.Manual
end

File +university/Section.m

%{
  -> university.Course
  -> university.Term
  section : char(1)
  ---
  room  :  varchar(12) # building and room code
%}
classdef Section < dj.Manual
end

File +university/CurrentTerm.m

%{
  ---
  -> university.Term
%}
classdef CurrentTerm < dj.Manual
end

File +university/Enroll.m

%{
  -> university.Section
  -> university.Student
%}
classdef Enroll < dj.Manual
end

File +university/LetterGrade.m

%{
  grade : char(2)
  ---
  points : decimal(3,2)
%}
classdef LetterGrade < dj.Manual
end

File +university/Grade.m

%{
  -> university.Enroll
  ---
  -> university.LetterGrade
%}
classdef Grade < dj.Manual
end

Example schema ERD

university example schema

Example schema for a university database. Tables contain data on students, departments, courses, etc.