CREATE TABLE AllowedResponse (
	-- Allowed Response (in which Question has allowedresponse-String) involves String,
	AllowedresponseString                   varchar NOT NULL,
	-- Allowed Response (in which Question has allowedresponse-String) and Question belongs to Questionnaire Section and Questionnaire Section has section-Nr,
	QuestionNaireSectionNr                  int NOT NULL,
	-- Allowed Response (in which Question has allowedresponse-String) and Question belongs to Questionnaire Section and Questionnaire Section belongs to Questionnaire and Questionnaire has Questionnaire Name,
	QuestionNaireSectionQuestionnaireName   varchar NOT NULL,
	-- Allowed Response (in which Question has allowedresponse-String) and Question has sequence-Nr,
	QuestionSequenceNr                      int NOT NULL,
	-- maybe Allowed Response requires follow-up by user acting in Role and Role has ID,
	RoleID                                  int NULL,
	-- Allowed Response has sequence-Nr,
	SequenceNr                              int NOT NULL,
	PRIMARY KEY(QuestionNaireSectionQuestionnaireName, QuestionNaireSectionNr, QuestionSequenceNr, AllowedresponseString)
)
GO

CREATE TABLE AptitudeTest (
	-- Aptitude Test has Aptitude Test Name,
	AptitudeTestName                        varchar(60) NOT NULL,
	PRIMARY KEY(AptitudeTestName)
)
GO

CREATE TABLE AptitudeTesting (
	-- Aptitude Testing (in which Candidate participates in Aptitude Test) and Aptitude Test has Aptitude Test Name,
	AptitudeTestName                        varchar(60) NOT NULL,
	-- maybe Aptitude Testing yielded Aptitude Test Result and Aptitude Test Result has Aptitude Test Result Code,
	AptitudeTestResultCode                  varchar(16) NULL,
	-- Aptitude Testing (in which Candidate participates in Aptitude Test) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	CandidateID                             int NOT NULL,
	-- Aptitude Testing is booked on Date,
	Date                                    datetime NOT NULL,
	-- maybe Aptitude Testing is booked at Time,
	Time                                    datetime NULL,
	PRIMARY KEY(CandidateID, AptitudeTestName),
	FOREIGN KEY (AptitudeTestName) REFERENCES AptitudeTest (AptitudeTestName)
)
GO

CREATE TABLE AuthenticationType (
	-- Authentication Type has Authentication Type Name,
	AuthenticationTypeName                  varchar(60) NOT NULL,
	-- Authentication Type is sensitive,
	IsSensitive                             bit NULL,
	PRIMARY KEY(AuthenticationTypeName)
)
GO

CREATE TABLE Candidate (
	-- maybe Candidate was born in birth-Country and Country has ISO3166Code3,
	BirthCountryISO3166Code3                varchar(3) NULL,
	-- maybe Candidate has Candidate Status and Candidate Status has value,
	CandidateStatusValue                    varchar NULL,
	-- maybe Candidate completed school in Year and Year has Year Nr,
	FinalYearAtSchoolNr                     int NULL CHECK(FinalYearAtSchoolNr >= 1900),
	-- Candidate has conviction,
	HasConviction                           bit NULL,
	-- maybe Candidate has completed School Yr Level and School Yr Level has School Yr Level Nr,
	HighestCompletedSchoolYrLevelNr         int NULL,
	-- Candidate is attending secondary school,
	IsAttendingSecondarySchool              bit NULL,
	-- Candidate is prepared to re-locate,
	IsPreparedToReLocate                    bit NULL,
	-- Candidate participated in work experience,
	ParticipatedInWorkExperience            bit NULL,
	-- Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	PersonID                                int NOT NULL,
	-- maybe Candidate has primarycitizenship-Country and Country has ISO3166Code3,
	PrimarycitizenshipCountryISO3166Code3   varchar(3) NULL,
	-- maybe Candidate has resume-Document and Document has Document ID,
	ResumeDocumentID                        int NULL,
	-- School Attendance (in which Candidate is attending secondary school) and maybe School Attendance is at current-School Yr Level and School Yr Level has School Yr Level Nr,
	SchoolAttendanceCurrentSchoolYrLevelNr  int NULL,
	-- School Attendance (in which Candidate is attending secondary school) and maybe School Attendance is at School and School has School Name,
	SchoolAttendanceSchoolName              varchar(60) NULL,
	-- School Attendance (in which Candidate is attending secondary school) and maybe School Attendance is in Suburb and Suburb has Suburb ID,
	SchoolAttendanceSuburbID                int NULL,
	-- maybe Candidate had status update on statusupdate-Date,
	StatusupdateDate                        datetime NULL,
	-- Candidate underwent medical examination,
	UnderwentMedicalExamination             bit NULL,
	-- Work Experience (in which Candidate participated in work experience) and maybe Work Experience was with Company and Company is a kind of Party and Party has Party ID,
	WorkExperienceCompanyID                 int NULL,
	-- Work Experience (in which Candidate participated in work experience) and maybe Work Experience has contact-Person and Person is a kind of Party and Party has Party ID,
	WorkExperienceContactPersonID           int NULL,
	-- maybe Candidate achieved year10-Subject Results Summary,
	Year10SubjectResultsSummary             varchar(120) NULL,
	-- maybe Candidate achieved year11-Subject Results Summary,
	Year11SubjectResultsSummary             varchar(120) NULL,
	-- maybe Candidate achieved year12-Subject Results Summary,
	Year12SubjectResultsSummary             varchar(120) NULL,
	PRIMARY KEY(PersonID)
)
GO

CREATE TABLE CandidateReferral (
	-- Candidate Referral (in which Candidate received Referral) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	CandidateID                             int NOT NULL,
	-- Candidate Referral (in which Candidate received Referral) and Referral has Referral Name,
	ReferralName                            varchar(60) NOT NULL,
	PRIMARY KEY(CandidateID, ReferralName),
	FOREIGN KEY (CandidateID) REFERENCES Candidate (PersonID)
)
GO

CREATE TABLE CandidateStatus (
	-- Candidate Status has value,
	CandidateStatusValue                    varchar NOT NULL,
	PRIMARY KEY(CandidateStatusValue)
)
GO

CREATE TABLE Company (
	-- Company has ABN,
	ABN                                     varchar(11) NOT NULL,
	-- maybe Company has ACN,
	ACN                                     varchar(9) NULL,
	-- Company has legal-Company Name,
	LegalCompanyName                        varchar(60) NOT NULL,
	-- Company is a kind of Party and Party has Party ID,
	PartyID                                 int NOT NULL,
	-- maybe Company uses trading-Company Name,
	TradingCompanyName                      varchar(60) NULL,
	-- maybe Company has website-URL,
	WebsiteURL                              varchar(512) NULL,
	PRIMARY KEY(PartyID),
	UNIQUE(ABN),
	UNIQUE(LegalCompanyName)
)
GO

CREATE VIEW dbo.Company_ACN (ACN) WITH SCHEMABINDING AS
	SELECT ACN FROM dbo.Company
	WHERE	ACN IS NOT NULL
GO

CREATE UNIQUE CLUSTERED INDEX IX_CompanyByACN ON dbo.Company_ACN(ACN)
GO

CREATE VIEW dbo.Company_TradingCompanyName (TradingCompanyName) WITH SCHEMABINDING AS
	SELECT TradingCompanyName FROM dbo.Company
	WHERE	TradingCompanyName IS NOT NULL
GO

CREATE UNIQUE CLUSTERED INDEX IX_CompanyByTradingCompanyName ON dbo.Company_TradingCompanyName(TradingCompanyName)
GO

CREATE TABLE Contact (
	-- maybe Contact is booked at actual-Date Time,
	ActualDateTime                          datetime NULL,
	-- Contact is booked for bookedfor-Person and Person is a kind of Party and Party has Party ID,
	BookedforPersonID                       int NOT NULL,
	-- Contact has Contact Method and Contact Method has Contact Method Name,
	ContactMethodName                       varchar NOT NULL,
	-- maybe Contact has Contact Report and maybe Contact Report was lodged by completedby-User and User is a kind of Person and Person is a kind of Party and Party has Party ID,
	ContactReportCompletedbyUserID          int NULL,
	-- maybe Contact has Contact Report and maybe Contact Report required follow-up File Note and File Note has File Note ID,
	ContactReportFileNoteID                 int NULL,
	-- maybe Contact has Contact Report and maybe Contact Report has overall-Comment,
	ContactReportOverallComment             varchar(4000) NULL,
	-- maybe Contact has Contact Report and maybe Contact Report was made during Placement and Placement (in which Worker fills Vacancy) and Vacancy has Vacancy ID,
	ContactReportPlacementVacancyID         int NULL,
	-- maybe Contact has Contact Report and maybe Contact Report was made during Placement and Placement (in which Worker fills Vacancy) and Worker is a kind of Person and Person is a kind of Party and Party has Party ID,
	ContactReportPlacementWorkerID          int NULL,
	-- Contact has Contact Type and Contact Type has Contact Type Name,
	ContactTypeName                         varchar NOT NULL,
	-- maybe Contact was carried out by Person and Person is a kind of Party and Party has Party ID,
	ContacterID                             int NULL,
	-- maybe Contact was carried out on Date Time,
	DateTime                                datetime NULL,
	-- Contact (in which Party requires contact on due-Date) involves Date,
	DueDate                                 datetime NOT NULL,
	-- Contact is cancelled,
	IsCancelled                             bit NULL,
	-- Contact is suspended,
	IsSuspended                             bit NULL,
	-- Contact (in which Party requires contact on due-Date) and Party has Party ID,
	PartyID                                 int NOT NULL,
	-- maybe Contact uses Questionnaire and Questionnaire has Questionnaire Name,
	QuestionnaireName                       varchar NULL,
	-- maybe Contact was derived from Scheduled Contact and Scheduled Contact (in which Contact Schedule requires contact after Contact Interval) and Contact Interval (in which contact is due after Count Contact Period) involves Contact Period,
	ScheduledContactIntervalContactPeriod   varchar NULL,
	-- maybe Contact was derived from Scheduled Contact and Scheduled Contact (in which Contact Schedule requires contact after Contact Interval) and Contact Interval (in which contact is due after Count Contact Period) involves Count,
	ScheduledContactIntervalCount           int NULL,
	-- maybe Contact was derived from Scheduled Contact and Scheduled Contact (in which Contact Schedule requires contact after Contact Interval) and Contact Schedule has Contact Schedule Name,
	ScheduledContactScheduleName            varchar NULL,
	PRIMARY KEY(PartyID, DueDate)
)
GO

CREATE TABLE ContactMethod (
	-- Contact Method has Contact Method Name,
	ContactMethodName                       varchar NOT NULL,
	PRIMARY KEY(ContactMethodName)
)
GO

CREATE TABLE ContactResponse (
	-- maybe Contact Response has Comment,
	Comment                                 varchar(4000) NULL,
	-- Contact Response (in which Contact Report reports Question was discussed) and Contact Report is for Contact and Contact (in which Party requires contact on due-Date) involves Date,
	ContactReportContactDueDate             datetime NOT NULL,
	-- Contact Response (in which Contact Report reports Question was discussed) and Contact Report is for Contact and Contact (in which Party requires contact on due-Date) and Party has Party ID,
	ContactReportContactPartyID             int NOT NULL,
	-- Contact Response (in which Contact Report reports Question was discussed) and Question belongs to Questionnaire Section and Questionnaire Section has section-Nr,
	QuestionNaireSectionNr                  int NOT NULL,
	-- Contact Response (in which Contact Report reports Question was discussed) and Question belongs to Questionnaire Section and Questionnaire Section belongs to Questionnaire and Questionnaire has Questionnaire Name,
	QuestionNaireSectionQuestionnaireName   varchar NOT NULL,
	-- Contact Response (in which Contact Report reports Question was discussed) and Question has sequence-Nr,
	QuestionSequenceNr                      int NOT NULL,
	PRIMARY KEY(ContactReportContactPartyID, ContactReportContactDueDate, QuestionNaireSectionQuestionnaireName, QuestionNaireSectionNr, QuestionSequenceNr),
	FOREIGN KEY (ContactReportContactPartyID, ContactReportContactDueDate) REFERENCES Contact (PartyID, DueDate)
)
GO

CREATE TABLE ContactRole (
	-- Contact Role (in which Person is Contact Kind contact for Department) involves Contact Kind,
	ContactKind                             varchar(32) NOT NULL,
	-- Contact Role (in which Person is Contact Kind contact for Department) and Department has Department ID,
	DepartmentID                            int NOT NULL,
	-- Contact Role is primary,
	IsPrimary                               bit NULL,
	-- Contact Role (in which Person is Contact Kind contact for Department) and Person is a kind of Party and Party has Party ID,
	PersonID                                int NOT NULL,
	PRIMARY KEY(PersonID, ContactKind, DepartmentID)
)
GO

CREATE TABLE ContactSchedule (
	-- Contact Schedule has Contact Schedule Name,
	ContactScheduleName                     varchar NOT NULL,
	PRIMARY KEY(ContactScheduleName)
)
GO

CREATE TABLE ContactSignature (
	-- Contact Signature (in which Contact Report has Digitised Signature for Contact Kind) involves Contact Kind,
	ContactKind                             varchar(32) NOT NULL,
	-- Contact Signature (in which Contact Report has Digitised Signature for Contact Kind) and Contact Report is for Contact and Contact (in which Party requires contact on due-Date) involves Date,
	ContactReportContactDueDate             datetime NOT NULL,
	-- Contact Signature (in which Contact Report has Digitised Signature for Contact Kind) and Contact Report is for Contact and Contact (in which Party requires contact on due-Date) and Party has Party ID,
	ContactReportContactPartyID             int NOT NULL,
	-- Contact Signature was applied on Date,
	Date                                    datetime NOT NULL,
	-- Contact Signature (in which Contact Report has Digitised Signature for Contact Kind) involves Digitised Signature,
	DigitisedSignature                      varchar(1024) NOT NULL,
	-- maybe Contact Signature was applied on behalf of Party and Party has Party ID,
	OnBehalfOfID                            int NULL,
	-- Contact Signature was applied by Person and Person is a kind of Party and Party has Party ID,
	PersonID                                int NOT NULL,
	PRIMARY KEY(ContactReportContactPartyID, ContactReportContactDueDate, DigitisedSignature, ContactKind),
	FOREIGN KEY (ContactReportContactPartyID, ContactReportContactDueDate) REFERENCES Contact (PartyID, DueDate)
)
GO

CREATE TABLE ContactType (
	-- Contact Type has Contact Type Name,
	ContactTypeName                         varchar NOT NULL,
	PRIMARY KEY(ContactTypeName)
)
GO

CREATE TABLE Correspondence (
	-- maybe Correspondence attracted Comment,
	Comment                                 varchar(4000) NULL,
	-- maybe Correspondence concerned Contact and Contact (in which Party requires contact on due-Date) involves Date,
	ContactDueDate                          datetime NULL,
	-- maybe Correspondence concerned Contact and Contact (in which Party requires contact on due-Date) and Party has Party ID,
	ContactPartyID                          int NULL,
	-- Correspondence (in which Party was in contact on DateMaybeTime by Correspondence Method) and Correspondence Method has Correspondence Method Name,
	CorrespondenceMethodName                varchar(60) NOT NULL,
	-- maybe Correspondence was generated using Correspondence Template and Correspondence Template has Correspondence Template Name,
	CorrespondenceTemplateName              varchar(60) NULL,
	-- Correspondence (in which Party was in contact on DateMaybeTime by Correspondence Method) and maybe DateMaybeTime has Time,
	DateMaybeTime                           datetime NULL,
	-- Correspondence (in which Party was in contact on DateMaybeTime by Correspondence Method) and DateMaybeTime has Date,
	DateMaybeTimeDate                       datetime NOT NULL,
	-- maybe Correspondence requires follow-up by follow-- up Date,
	FollowUpDate                            datetime NULL,
	-- follow-up to Correspondence is complete,
	FollowUpToIsComplete                    bit NULL,
	-- Correspondence (in which Party was in contact on DateMaybeTime by Correspondence Method) and Party has Party ID,
	PartyID                                 int NOT NULL,
	-- maybe Correspondence has purpose-Name,
	PurposeName                             varchar(60) NULL,
	-- maybe Correspondence has received-Document and Document has Document ID,
	ReceivedDocumentID                      int NULL,
	-- maybe Correspondence has sent-Document and Document has Document ID,
	SentDocumentID                          int NULL,
	-- maybe Correspondence was handled by Person and Person is a kind of Party and Party has Party ID,
	StaffMemberID                           int NULL,
	UNIQUE(PartyID, DateMaybeTimeDate, DateMaybeTime, CorrespondenceMethodName),
	FOREIGN KEY (ContactPartyID, ContactDueDate) REFERENCES Contact (PartyID, DueDate)
)
GO

CREATE TABLE CorrespondenceMethod (
	-- Correspondence Method has Correspondence Method Name,
	CorrespondenceMethodName                varchar(60) NOT NULL,
	PRIMARY KEY(CorrespondenceMethodName)
)
GO

CREATE TABLE Country (
	-- Country is called Country Name,
	CountryName                             varchar(60) NOT NULL,
	-- Country has ISO3166Code2,
	ISO3166Code2                            varchar(2) NOT NULL,
	-- Country has ISO3166Code3,
	ISO3166Code3                            varchar(3) NOT NULL,
	-- Country has ISO3166Numeric3,
	ISO3166Numeric3                         int NOT NULL,
	PRIMARY KEY(ISO3166Code3),
	UNIQUE(CountryName),
	UNIQUE(ISO3166Code2),
	UNIQUE(ISO3166Numeric3)
)
GO

CREATE TABLE DashboardWidget (
	-- Dashboard Widget was created at Date Time,
	CreatedAt                               datetime NOT NULL,
	-- Dashboard Widget (in which Dashboard contains Widget) and Dashboard belongs to User and User is a kind of Person and Person is a kind of Party and Party has Party ID,
	DashboardUserID                         int NOT NULL,
	-- Dashboard Widget is active,
	IsActive                                bit NULL,
	-- Dashboard Widget was updated at Date Time,
	UpdatedAt                               datetime NOT NULL,
	-- Dashboard Widget has weight-Nr,
	WeightNr                                int NOT NULL,
	-- Dashboard Widget (in which Dashboard contains Widget) and Widget has Widget Name,
	WidgetName                              varchar NOT NULL,
	PRIMARY KEY(DashboardUserID, WidgetName)
)
GO

CREATE TABLE Department (
	-- Department is part of Company and Company is a kind of Party and Party has Party ID,
	CompanyID                               int NOT NULL,
	-- Department has Department ID,
	DepartmentID                            int IDENTITY NOT NULL,
	-- Department is called Department Name,
	DepartmentName                          varchar NOT NULL,
	-- maybe Department belongs to parent-Department and Department has Department ID,
	ParentDepartmentID                      int NULL,
	PRIMARY KEY(DepartmentID),
	FOREIGN KEY (CompanyID) REFERENCES Company (PartyID),
	FOREIGN KEY (ParentDepartmentID) REFERENCES Department (DepartmentID)
)
GO

CREATE VIEW dbo.Department_CompanyIDParentDepartmentIDName (CompanyID, ParentDepartmentID, DepartmentName) WITH SCHEMABINDING AS
	SELECT CompanyID, ParentDepartmentID, DepartmentName FROM dbo.Department
	WHERE	ParentDepartmentID IS NOT NULL
GO

CREATE UNIQUE CLUSTERED INDEX IX_DepartmentByCompanyIDParentDepartmentIDDepartmentName ON dbo.Department_CompanyIDParentDepartmentIDName(CompanyID, ParentDepartmentID, DepartmentName)
GO

CREATE TABLE Document (
	-- maybe Document was recorded on Date,
	Date                                    datetime NULL,
	-- Document is in Document Format and Document Format has Document Format Code,
	DocumentFormatCode                      varchar(16) NOT NULL,
	-- Document has Document ID,
	DocumentID                              int IDENTITY NOT NULL,
	-- Document is scanned,
	IsScanned                               bit NULL,
	-- maybe Document was recorded by Person and Person is a kind of Party and Party has Party ID,
	PersonID                                int NULL,
	-- maybe Document is stored in URL,
	URL                                     varchar(512) NULL,
	PRIMARY KEY(DocumentID)
)
GO

CREATE VIEW dbo.Document_URL (URL) WITH SCHEMABINDING AS
	SELECT URL FROM dbo.Document
	WHERE	URL IS NOT NULL
GO

CREATE UNIQUE CLUSTERED INDEX IX_DocumentByURL ON dbo.Document_URL(URL)
GO

CREATE TABLE DocumentFormat (
	-- Document Format has Document Format Code,
	DocumentFormatCode                      varchar(16) NOT NULL,
	PRIMARY KEY(DocumentFormatCode)
)
GO

CREATE TABLE Employment (
	-- Employment (in which Person works for Employer) and Person is a kind of Party and Party has Party ID,
	EmployeeID                              int NOT NULL,
	-- Employment (in which Person works for Employer) and Employer is a kind of Company and Company is a kind of Party and Party has Party ID,
	EmployerID                              int NOT NULL,
	-- Employment is as trainee,
	IsAsTrainee                             bit NULL,
	-- maybe Employment confers Job Title and Job Title has Job Title Name,
	JobTitleName                            varchar(60) NULL,
	-- maybe Employment is under PayrollNr,
	PayrollNr                               varchar(20) NULL,
	-- maybe Employment is at worksite-Location and Location (in which Party has Location Role at Address) and Address is in Country and Country has ISO3166Code3,
	WorksiteLocationAddressCountryISO3166Code3 varchar(3) NULL,
	-- maybe Employment is at worksite-Location and Location (in which Party has Location Role at Address) and Address is in State and State has State ID,
	WorksiteLocationAddressStateID          int NULL,
	-- maybe Employment is at worksite-Location and Location (in which Party has Location Role at Address) and Address has Street,
	WorksiteLocationAddressStreet           varchar(64) NULL,
	-- maybe Employment is at worksite-Location and Location (in which Party has Location Role at Address) and Address has Suburb and Suburb has Suburb ID,
	WorksiteLocationAddressSuburbID         int NULL,
	-- maybe Employment is at worksite-Location and Location (in which Party has Location Role at Address) and Party has Party ID,
	WorksiteLocationPartyID                 int NULL,
	-- maybe Employment is at worksite-Location and Location (in which Party has Location Role at Address) and Location Role has value,
	WorksiteLocationRoleValue               varchar(32) NULL,
	PRIMARY KEY(EmployeeID, EmployerID),
	FOREIGN KEY (EmployerID) REFERENCES Company (PartyID)
)
GO

CREATE TABLE FileNote (
	-- maybe File Note applies to Aptitude Testing and Aptitude Testing (in which Candidate participates in Aptitude Test) and Aptitude Test has Aptitude Test Name,
	AptitudeTestingAptitudeTestName         varchar(60) NULL,
	-- maybe File Note applies to Aptitude Testing and Aptitude Testing (in which Candidate participates in Aptitude Test) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	AptitudeTestingCandidateID              int NULL,
	-- maybe File Note has attached-Document and Document has Document ID,
	AttachedDocumentID                      int NULL,
	-- File Note contains Comment,
	Comment                                 varchar(4000) NOT NULL,
	-- maybe File Note follow-up was completed by completedby-User and User is a kind of Person and Person is a kind of Party and Party has Party ID,
	CompletedbyUserID                       int NULL,
	-- maybe File Note was followed up on completion-Date,
	CompletionDate                          datetime NULL,
	-- File Note was created on created-Date,
	CreatedDate                             datetime NOT NULL,
	-- File Note has File Note ID,
	FileNoteID                              int IDENTITY NOT NULL,
	-- maybe File Note is created from File Note Template and File Note Template has File Note Template Name,
	FileNoteTemplateName                    varchar NULL,
	-- File Note is of File Note Type and File Note Type has value,
	FileNoteTypeValue                       varchar NOT NULL,
	-- maybe File Note requires followup by followup-Date,
	FollowupDate                            datetime NULL,
	-- maybe File Note requires followup by followup-User and User is a kind of Person and Person is a kind of Party and Party has Party ID,
	FollowupUserID                          int NULL,
	-- maybe File Note applies to Interview and Interview (in which Candidate participated in interview with Employer on DateMaybeTime) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	InterviewCandidateID                    int NULL,
	-- maybe File Note applies to Interview and Interview (in which Candidate participated in interview with Employer on DateMaybeTime) and maybe DateMaybeTime has Time,
	InterviewDateMaybeTime                  datetime NULL,
	-- maybe File Note applies to Interview and Interview (in which Candidate participated in interview with Employer on DateMaybeTime) and DateMaybeTime has Date,
	InterviewDateMaybeTimeDate              datetime NULL,
	-- maybe File Note applies to Interview and Interview (in which Candidate participated in interview with Employer on DateMaybeTime) and Employer is a kind of Company and Company is a kind of Party and Party has Party ID,
	InterviewEmployerID                     int NULL,
	-- maybe File Note applies to Person and Person is a kind of Party and Party has Party ID,
	PersonID                                int NULL,
	-- maybe File Note applies to Placement Application and Placement Application (in which Person applied for Vacancy on application-Date) and Person is a kind of Party and Party has Party ID,
	PlacementApplicationPersonID            int NULL,
	-- maybe File Note applies to Placement Application and Placement Application (in which Person applied for Vacancy on application-Date) and Vacancy has Vacancy ID,
	PlacementApplicationVacancyID           int NULL,
	-- maybe File Note applies to Previous Employment and Previous Employment (in which Candidate was employed with Previous Employer) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	PreviousEmploymentCandidateID           int NULL,
	-- maybe File Note applies to Previous Employment and Previous Employment (in which Candidate was employed with Previous Employer) and Previous Employer has Company Name,
	PreviousEmploymentPreviousEmployerCompanyName varchar(60) NULL,
	-- maybe File Note applies to Reference Check and Reference Check checked Personal Reference and Personal Reference is for Candidate and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	ReferenceCheckPersonalReferenceCandidateID int NULL,
	-- maybe File Note applies to Reference Check and Reference Check checked Personal Reference and maybe Personal Reference is from Previous Employer and Previous Employer has Company Name,
	ReferenceCheckPersonalReferencePreviousEmployerCompanyName varchar(60) NULL,
	-- maybe File Note applies to Reference Check and Reference Check checked Personal Reference and Personal Reference is by referee-Name,
	ReferenceCheckPersonalReferenceRefereeName varchar(60) NULL,
	-- maybe File Note applies to School Achievement and School Achievement is of Candidate and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	SchoolAchievementCandidateID            int NULL,
	-- maybe File Note applies to Vacancy and Vacancy has Vacancy ID,
	VacancyID                               int NULL,
	PRIMARY KEY(FileNoteID),
	FOREIGN KEY (AptitudeTestingCandidateID, AptitudeTestingAptitudeTestName) REFERENCES AptitudeTesting (CandidateID, AptitudeTestName),
	FOREIGN KEY (SchoolAchievementCandidateID) REFERENCES Candidate (PersonID),
	FOREIGN KEY (AttachedDocumentID) REFERENCES Document (DocumentID)
)
GO

CREATE TABLE FileNoteTemplate (
	-- maybe File Note Template contains Comment,
	Comment                                 varchar(4000) NULL,
	-- File Note Template has File Note Template Name,
	FileNoteTemplateName                    varchar NOT NULL,
	-- maybe File Note Template has followup-User and User is a kind of Person and Person is a kind of Party and Party has Party ID,
	FollowupUserID                          int NULL,
	-- maybe File Note Template has followupdays-Count,
	FollowupdaysCount                       int NULL,
	-- File Note Template is published,
	IsPublished                             bit NULL,
	-- maybe File Note Template has type-Name,
	TypeName                                varchar(60) NULL,
	PRIMARY KEY(FileNoteTemplateName)
)
GO

CREATE TABLE FileNoteType (
	-- File Note Type has value,
	FileNoteTypeValue                       varchar NOT NULL,
	PRIMARY KEY(FileNoteTypeValue)
)
GO

CREATE TABLE Filter (
	-- Filter (in which Search has Search Facet Value for Search Facet) and Search Facet has Search Facet ID,
	SearchFacetID                           int NOT NULL,
	-- Filter (in which Search has Search Facet Value for Search Facet) involves Search Facet Value,
	SearchFacetValue                        varchar NOT NULL,
	-- Filter (in which Search has Search Facet Value for Search Facet) and Search has Search ID,
	SearchID                                int NOT NULL,
	PRIMARY KEY(SearchID, SearchFacetID)
)
GO

CREATE TABLE Gender (
	-- Gender has Gender Code,
	GenderCode                              varchar(16) NOT NULL,
	-- Gender has gender-Name,
	GenderName                              varchar(60) NOT NULL,
	PRIMARY KEY(GenderCode)
)
GO

CREATE TABLE Interview (
	-- Interview (in which Candidate participated in interview with Employer on DateMaybeTime) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	CandidateID                             int NOT NULL,
	-- Interview (in which Candidate participated in interview with Employer on DateMaybeTime) and maybe DateMaybeTime has Time,
	DateMaybeTime                           datetime NULL,
	-- Interview (in which Candidate participated in interview with Employer on DateMaybeTime) and DateMaybeTime has Date,
	DateMaybeTimeDate                       datetime NOT NULL,
	-- Interview (in which Candidate participated in interview with Employer on DateMaybeTime) and Employer is a kind of Company and Company is a kind of Party and Party has Party ID,
	EmployerID                              int NOT NULL,
	-- maybe Interview is of Interview Type,
	InterviewType                           varchar(60) NULL,
	-- Interview was recorded by Person and Person is a kind of Party and Party has Party ID,
	PersonID                                int NOT NULL,
	-- maybe Interview is for Placement Application and Placement Application (in which Person applied for Vacancy on application-Date) and Person is a kind of Party and Party has Party ID,
	PlacementApplicationPersonID            int NULL,
	-- maybe Interview is for Placement Application and Placement Application (in which Person applied for Vacancy on application-Date) and Vacancy has Vacancy ID,
	PlacementApplicationVacancyID           int NULL,
	UNIQUE(CandidateID, EmployerID, DateMaybeTimeDate, DateMaybeTime),
	FOREIGN KEY (CandidateID) REFERENCES Candidate (PersonID),
	FOREIGN KEY (EmployerID) REFERENCES Company (PartyID)
)
GO

CREATE TABLE Language (
	-- Language has Language Name,
	LanguageName                            varchar(60) NOT NULL,
	PRIMARY KEY(LanguageName)
)
GO

CREATE TABLE LanguageSpoken (
	-- Language Spoken (in which Candidate speaks Language) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	CandidateID                             int NOT NULL,
	-- Language Spoken (in which Candidate speaks Language) and Language has Language Name,
	LanguageName                            varchar(60) NOT NULL,
	PRIMARY KEY(CandidateID, LanguageName),
	FOREIGN KEY (CandidateID) REFERENCES Candidate (PersonID),
	FOREIGN KEY (LanguageName) REFERENCES Language (LanguageName)
)
GO

CREATE TABLE Location (
	-- Location (in which Party has Location Role at Address) and Address is in Country and Country has ISO3166Code3,
	AddressCountryISO3166Code3              varchar(3) NOT NULL,
	-- Location (in which Party has Location Role at Address) and Address is in State and State has State ID,
	AddressStateID                          int NOT NULL,
	-- Location (in which Party has Location Role at Address) and Address has Street,
	AddressStreet                           varchar(64) NOT NULL,
	-- Location (in which Party has Location Role at Address) and Address has Suburb and Suburb has Suburb ID,
	AddressSuburbID                         int NOT NULL,
	-- Location (in which Party has Location Role at Address) and Location Role has value,
	LocationRoleValue                       varchar(32) NOT NULL,
	-- Location (in which Party has Location Role at Address) and Party has Party ID,
	PartyID                                 int NOT NULL,
	-- maybe Location has short-Name,
	ShortName                               varchar(60) NULL,
	PRIMARY KEY(PartyID, LocationRoleValue, AddressStreet, AddressSuburbID, AddressStateID, AddressCountryISO3166Code3),
	FOREIGN KEY (AddressCountryISO3166Code3) REFERENCES Country (ISO3166Code3)
)
GO

CREATE TABLE LocationRole (
	-- Location Role has value,
	LocationRoleValue                       varchar(32) NOT NULL,
	PRIMARY KEY(LocationRoleValue)
)
GO

CREATE TABLE Party (
	-- Party has Party ID,
	PartyID                                 int IDENTITY NOT NULL,
	-- Party is of Party Type and Party Type has Party Type Code,
	PartyTypeCode                           varchar(16) NOT NULL CHECK(PartyTypeCode = 'Company' OR PartyTypeCode = 'Person'),
	PRIMARY KEY(PartyID)
)
GO

CREATE TABLE PartyAuthentication (
	-- Party Authentication (in which Party has Authentication Type of Authentication Value) and Authentication Type has Authentication Type Name,
	AuthenticationTypeName                  varchar(60) NOT NULL,
	-- Party Authentication (in which Party has Authentication Type of Authentication Value) involves Authentication Value,
	AuthenticationValue                     varchar(80) NOT NULL,
	-- Party Authentication (in which Party has Authentication Type of Authentication Value) and Party has Party ID,
	PartyID                                 int NOT NULL,
	PRIMARY KEY(PartyID, AuthenticationTypeName),
	FOREIGN KEY (AuthenticationTypeName) REFERENCES AuthenticationType (AuthenticationTypeName),
	FOREIGN KEY (PartyID) REFERENCES Party (PartyID)
)
GO

CREATE TABLE PartyPhone (
	-- Party Phone can receive fax,
	CanReceiveFax                           bit NULL,
	-- Party Phone can receive sms,
	CanReceiveSms                           bit NULL,
	-- Party Phone (in which Party has Phone Role phone on Phone Number) and Party has Party ID,
	PartyID                                 int NOT NULL,
	-- Party Phone (in which Party has Phone Role phone on Phone Number) involves Phone Number,
	PhoneNumber                             varchar(32) NOT NULL,
	-- Party Phone (in which Party has Phone Role phone on Phone Number) and Phone Role has value,
	PhoneRoleValue                          varchar(20) NOT NULL,
	PRIMARY KEY(PartyID, PhoneRoleValue),
	FOREIGN KEY (PartyID) REFERENCES Party (PartyID)
)
GO

CREATE TABLE PartyPreference (
	-- Party Preference (in which Party sets Settable Preference to Preference Value) and Party has Party ID,
	PartyID                                 int NOT NULL,
	-- Party Preference has Party Preference ID,
	PartyPreferenceID                       int IDENTITY NOT NULL,
	-- Party Preference (in which Party sets Settable Preference to Preference Value) involves Preference Value,
	PreferenceValue                         varchar NOT NULL,
	-- Party Preference (in which Party sets Settable Preference to Preference Value) and Settable Preference has Settable Preference Name,
	SettablePreferenceName                  varchar NOT NULL,
	PRIMARY KEY(PartyPreferenceID),
	UNIQUE(PartyID, SettablePreferenceName),
	FOREIGN KEY (PartyID) REFERENCES Party (PartyID)
)
GO

CREATE TABLE Person (
	-- maybe Person was born on birth-Date,
	BirthDate                               datetime NULL,
	-- maybe Person is a Driver and maybe Driver drives Vehicle Description,
	DriverVehicleDescription                varchar(32) NULL,
	-- maybe Person is a Driver and maybe Driver is Vehicle User Role of private vehicle,
	DriverVehicleUserRole                   varchar(20) NULL CHECK(DriverVehicleUserRole = 'owner' OR DriverVehicleUserRole = 'user'),
	-- maybe Person uses EmailAddress,
	EmailAddress                            varchar(80) NULL,
	-- maybe Person has family-Name,
	FamilyName                              varchar(60) NULL,
	-- maybe Person is of Gender and Gender has Gender Code,
	GenderCode                              varchar(16) NULL,
	-- Person is called given-Name,
	GivenName                               varchar(60) NOT NULL,
	-- maybe Person has middle-Name,
	MiddleName                              varchar(60) NULL,
	-- Person is a kind of Party and Party has Party ID,
	PartyID                                 int NOT NULL,
	-- maybe Person has Photo and Photo has Photo ID,
	PhotoID                                 int NULL,
	-- maybe Person prefers preferred-Name,
	PreferredName                           varchar(60) NULL,
	-- maybe Person is addressed by Salutation and Salutation has Salutation Code,
	SalutationCode                          varchar(16) NULL,
	PRIMARY KEY(PartyID),
	FOREIGN KEY (GenderCode) REFERENCES Gender (GenderCode),
	FOREIGN KEY (PartyID) REFERENCES Party (PartyID)
)
GO

CREATE TABLE PersonalCharacterisation (
	-- Personal Characterisation (in which Candidate has Personal Characteristic) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	CandidateID                             int NOT NULL,
	-- Personal Characterisation (in which Candidate has Personal Characteristic) and Personal Characteristic has Personal Characteristic Name,
	PersonalCharacteristicName              varchar(60) NOT NULL,
	PRIMARY KEY(CandidateID, PersonalCharacteristicName),
	FOREIGN KEY (CandidateID) REFERENCES Candidate (PersonID)
)
GO

CREATE TABLE PersonalCharacteristic (
	-- Personal Characteristic has Personal Characteristic Name,
	PersonalCharacteristicName              varchar(60) NOT NULL,
	PRIMARY KEY(PersonalCharacteristicName)
)
GO

CREATE TABLE PersonalEmergencyContact (
	-- Personal Emergency Contact has Name,
	ContactName                             varchar(60) NOT NULL,
	-- Personal Emergency Contact is for Person and Person is a kind of Party and Party has Party ID,
	PersonID                                int NOT NULL,
	-- Personal Emergency Contact has Phone Number,
	PhoneNumber                             varchar(32) NOT NULL,
	-- maybe Personal Emergency Contact has Relationship and Relationship has Relationship Code,
	RelationshipCode                        varchar(16) NULL,
	PRIMARY KEY(PersonID, ContactName),
	FOREIGN KEY (PersonID) REFERENCES Person (PartyID)
)
GO

CREATE TABLE PersonalReference (
	-- Personal Reference is for Candidate and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	CandidateID                             int NOT NULL,
	-- maybe Personal Reference has contact-Phone Number,
	ContactPhoneNumber                      varchar(32) NULL,
	-- maybe Personal Reference is for Job Title and Job Title has Job Title Name,
	JobTitleName                            varchar(60) NULL,
	-- maybe Personal Reference is from Previous Employer and Previous Employer has Company Name,
	PreviousEmployerCompanyName             varchar(60) NULL,
	-- Personal Reference is by referee-Name,
	RefereeName                             varchar(60) NOT NULL,
	-- maybe Personal Reference was checked in Reference Check and maybe Reference Check confirmed employment from commencement-Date,
	ReferenceCheckCommencementDate          datetime NULL,
	-- maybe Personal Reference was checked in Reference Check and maybe Reference Check confirmed employment until completion-Date,
	ReferenceCheckCompletionDate            datetime NULL,
	-- maybe Personal Reference was checked in Reference Check and Reference Check was made on Date,
	ReferenceCheckDate                      datetime NULL,
	-- maybe Personal Reference was checked in Reference Check and Reference Check was made by Person and Person is a kind of Party and Party has Party ID,
	ReferenceCheckPersonID                  int NULL,
	-- maybe Personal Reference was checked in Reference Check and maybe Reference Check was with respondent-Name,
	ReferenceCheckRespondentName            varchar(60) NULL,
	UNIQUE(CandidateID, PreviousEmployerCompanyName, RefereeName),
	FOREIGN KEY (CandidateID) REFERENCES Candidate (PersonID),
	FOREIGN KEY (ReferenceCheckPersonID) REFERENCES Person (PartyID)
)
GO

CREATE TABLE PhoneRole (
	-- Phone Role has value,
	PhoneRoleValue                          varchar(20) NOT NULL,
	PRIMARY KEY(PhoneRoleValue)
)
GO

CREATE TABLE Placement (
	-- maybe Placement commences on commencement-Date,
	CommencementDate                        datetime NULL,
	-- maybe Placement is complete on completion-Date,
	CompletionDate                          datetime NULL,
	-- maybe Placement nominally ends on nominalend-Date,
	NominalendDate                          datetime NULL,
	-- maybe Placement ended in Placement Result and Placement Result has Placement Result Code,
	PlacementResultCode                     varchar(16) NULL,
	-- maybe Placement is of Placement Type and Placement Type has Placement Type Code,
	PlacementTypeCode                       varchar(16) NULL,
	-- maybe Placement issued tools on toolissue-Date,
	ToolissueDate                           datetime NULL,
	-- maybe Placement tools were returned on toolreturn-Date,
	ToolreturnDate                          datetime NULL,
	-- Placement (in which Worker fills Vacancy) and Vacancy has Vacancy ID,
	VacancyID                               int NOT NULL,
	-- Placement (in which Worker fills Vacancy) and Worker is a kind of Person and Person is a kind of Party and Party has Party ID,
	WorkerID                                int NOT NULL,
	PRIMARY KEY(WorkerID, VacancyID)
)
GO

CREATE TABLE PlacementApplication (
	-- Placement Application (in which Person applied for Vacancy on application-Date) involves Date,
	ApplicationDate                         datetime NOT NULL,
	-- maybe Placement Application was created by Person and Person is a kind of Party and Party has Party ID,
	CreatorID                               int NULL,
	-- maybe Placement Application resulted from referral on Date,
	Date                                    datetime NULL,
	-- maybe Placement Application was updated on Date,
	LastUpdatedDate                         datetime NULL,
	-- Placement Application (in which Person applied for Vacancy on application-Date) and Person is a kind of Party and Party has Party ID,
	PersonID                                int NOT NULL,
	-- maybe Placement Application yielded Placement Application Result and Placement Application Result has Placement Application Result Code,
	PlacementApplicationResultCode          varchar(16) NULL,
	-- maybe Placement Application was updated by Person and Person is a kind of Party and Party has Party ID,
	UpdaterID                               int NULL,
	-- Placement Application (in which Person applied for Vacancy on application-Date) and Vacancy has Vacancy ID,
	VacancyID                               int NOT NULL,
	PRIMARY KEY(PersonID, VacancyID),
	FOREIGN KEY (CreatorID) REFERENCES Person (PartyID),
	FOREIGN KEY (PersonID) REFERENCES Person (PartyID),
	FOREIGN KEY (UpdaterID) REFERENCES Person (PartyID)
)
GO

CREATE TABLE PreviousEmployment (
	-- Previous Employment (in which Candidate was employed with Previous Employer) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	CandidateID                             int NOT NULL,
	-- maybe Previous Employment was until YearMaybeMonth and maybe YearMaybeMonth was in Month and Month has Month Nr,
	EmploymentEndMonthNr                    int NULL CHECK((EmploymentEndMonthNr >= 1 AND EmploymentEndMonthNr <= 12)),
	-- maybe Previous Employment was until YearMaybeMonth and YearMaybeMonth was in Year and Year has Year Nr,
	EmploymentEndYearNr                     int NULL CHECK(EmploymentEndYearNr >= 1900),
	-- maybe Previous Employment was from YearMaybeMonth and maybe YearMaybeMonth was in Month and Month has Month Nr,
	EmploymentStartMonthNr                  int NULL CHECK((EmploymentStartMonthNr >= 1 AND EmploymentStartMonthNr <= 12)),
	-- maybe Previous Employment was from YearMaybeMonth and YearMaybeMonth was in Year and Year has Year Nr,
	EmploymentStartYearNr                   int NULL CHECK(EmploymentStartYearNr >= 1900),
	-- maybe Previous Employment was under Job Title and Job Title has Job Title Name,
	JobTitleName                            varchar(60) NULL,
	-- Previous Employment (in which Candidate was employed with Previous Employer) and Previous Employer has Company Name,
	PreviousEmployerCompanyName             varchar(60) NOT NULL,
	PRIMARY KEY(CandidateID, PreviousEmployerCompanyName),
	FOREIGN KEY (CandidateID) REFERENCES Candidate (PersonID)
)
GO

CREATE TABLE Question (
	-- Question has question-String,
	QuestionString                          varchar NOT NULL,
	-- Question belongs to Questionnaire Section and Questionnaire Section has section-Nr,
	QuestionnaireSectionNr                  int NOT NULL,
	-- Question belongs to Questionnaire Section and Questionnaire Section belongs to Questionnaire and Questionnaire has Questionnaire Name,
	QuestionnaireSectionQuestionnaireName   varchar NOT NULL,
	-- Question has sequence-Nr,
	SequenceNr                              int NOT NULL,
	PRIMARY KEY(QuestionnaireSectionQuestionnaireName, QuestionnaireSectionNr, SequenceNr)
)
GO

CREATE TABLE QuestionnaireSection (
	-- Questionnaire Section belongs to Questionnaire and Questionnaire has Questionnaire Name,
	QuestionnaireName                       varchar NOT NULL,
	-- Questionnaire Section has section-Name,
	SectionName                             varchar(60) NOT NULL,
	-- Questionnaire Section has section-Nr,
	SectionNr                               int NOT NULL,
	PRIMARY KEY(QuestionnaireName, SectionNr)
)
GO

CREATE TABLE Referral (
	-- Referral has Referral Name,
	ReferralName                            varchar(60) NOT NULL,
	PRIMARY KEY(ReferralName)
)
GO

CREATE TABLE Role (
	-- Role was created at Date Time,
	CreatedAt                               datetime NOT NULL,
	-- Role has ID,
	ID                                      int IDENTITY NOT NULL,
	-- Role is called Name,
	Name                                    varchar(60) NOT NULL,
	-- maybe Role covers Resource and Resource has Resource ID,
	ResourceID                              int NULL,
	-- maybe Role covers Resource Type,
	ResourceType                            varchar(60) NULL,
	-- maybe Role was updated at Date Time,
	UpdatedAt                               datetime NULL,
	PRIMARY KEY(ID),
	UNIQUE(Name)
)
GO

CREATE TABLE Salutation (
	-- Salutation has Salutation Code,
	SalutationCode                          varchar(16) NOT NULL,
	PRIMARY KEY(SalutationCode)
)
GO

CREATE TABLE ScheduledContact (
	-- Scheduled Contact (in which Contact Schedule requires contact after Contact Interval) and Contact Interval (in which contact is due after Count Contact Period) involves Contact Period,
	ContactIntervalContactPeriod            varchar NOT NULL CHECK(ContactIntervalContactPeriod = 'day' OR ContactIntervalContactPeriod = 'month' OR ContactIntervalContactPeriod = 'week'),
	-- Scheduled Contact (in which Contact Schedule requires contact after Contact Interval) and Contact Interval (in which contact is due after Count Contact Period) involves Count,
	ContactIntervalCount                    int NOT NULL,
	-- maybe Scheduled Contact has Contact Method and Contact Method has Contact Method Name,
	ContactMethodName                       varchar NULL,
	-- Scheduled Contact (in which Contact Schedule requires contact after Contact Interval) and Contact Schedule has Contact Schedule Name,
	ContactScheduleName                     varchar NOT NULL,
	-- maybe Scheduled Contact is of Contact Type and Contact Type has Contact Type Name,
	ContactTypeName                         varchar NULL,
	-- Scheduled Contact is apprenticeship completion check,
	IsApprenticeshipCompletionCheck         bit NULL,
	-- maybe Scheduled Contact uses Questionnaire and Questionnaire has Questionnaire Name,
	QuestionnaireName                       varchar NULL,
	-- maybe Scheduled Contact repeats on repeat-Contact Interval and Contact Interval (in which contact is due after Count Contact Period) involves Contact Period,
	RepeatContactIntervalContactPeriod      varchar NULL CHECK(RepeatContactIntervalContactPeriod = 'day' OR RepeatContactIntervalContactPeriod = 'month' OR RepeatContactIntervalContactPeriod = 'week'),
	-- maybe Scheduled Contact repeats on repeat-Contact Interval and Contact Interval (in which contact is due after Count Contact Period) involves Count,
	RepeatContactIntervalCount              int NULL,
	PRIMARY KEY(ContactScheduleName, ContactIntervalCount, ContactIntervalContactPeriod),
	FOREIGN KEY (ContactMethodName) REFERENCES ContactMethod (ContactMethodName),
	FOREIGN KEY (ContactScheduleName) REFERENCES ContactSchedule (ContactScheduleName),
	FOREIGN KEY (ContactTypeName) REFERENCES ContactType (ContactTypeName)
)
GO

CREATE TABLE Search (
	-- Search is public,
	IsPublic                                bit NULL,
	-- Search has Search ID,
	SearchID                                int IDENTITY NOT NULL,
	-- Search has Search Title,
	SearchTitle                             varchar(60) NOT NULL,
	-- Search was saved by User and User is a kind of Person and Person is a kind of Party and Party has Party ID,
	UserID                                  int NOT NULL,
	PRIMARY KEY(SearchID)
)
GO

CREATE TABLE SearchFacet (
	-- Search Facet has Search Facet ID,
	SearchFacetID                           int IDENTITY NOT NULL,
	-- Search Facet has Search Facet Name,
	SearchFacetName                         varchar NOT NULL,
	PRIMARY KEY(SearchFacetID),
	UNIQUE(SearchFacetName)
)
GO

CREATE TABLE SettablePreference (
	-- Settable Preference is of Data Type and Data Type has Data Type Name,
	DataTypeName                            varchar NOT NULL,
	-- maybe Settable Preference is restricted by Data Value Restriction,
	DataValueRestriction                    varchar NULL,
	-- Settable Preference has Settable Preference Name,
	SettablePreferenceName                  varchar NOT NULL,
	PRIMARY KEY(SettablePreferenceName)
)
GO

CREATE TABLE SkillsCertificate (
	-- Skills Certificate (in which Candidate has Skills Certification) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	CandidateID                             int NOT NULL,
	-- Skills Certificate (in which Candidate has Skills Certification) and Skills Certification has Skills Certification Name,
	SkillsCertificationName                 varchar(60) NOT NULL,
	PRIMARY KEY(CandidateID, SkillsCertificationName),
	FOREIGN KEY (CandidateID) REFERENCES Candidate (PersonID)
)
GO

CREATE TABLE SkillsCertification (
	-- maybe Skills Certification has certificate-Code,
	CertificateCode                         varchar(16) NULL,
	-- Skills Certification has Skills Certification Name,
	SkillsCertificationName                 varchar(60) NOT NULL,
	PRIMARY KEY(SkillsCertificationName)
)
GO

CREATE TABLE State (
	-- State has State Code,
	StateCode                               varchar(3) NOT NULL,
	-- State has State ID,
	StateID                                 int IDENTITY NOT NULL,
	-- State has State Name,
	StateName                               varchar(60) NOT NULL,
	PRIMARY KEY(StateID),
	UNIQUE(StateCode),
	UNIQUE(StateName)
)
GO

CREATE TABLE Suburb (
	-- Suburb has Postcode,
	Postcode                                varchar(12) NOT NULL,
	-- maybe Suburb is in State and State has State ID,
	StateID                                 int NULL,
	-- Suburb has Suburb ID,
	SuburbID                                int IDENTITY NOT NULL,
	-- Suburb has Suburb Name,
	SuburbName                              varchar(60) NOT NULL,
	PRIMARY KEY(SuburbID),
	UNIQUE(SuburbName, Postcode),
	FOREIGN KEY (StateID) REFERENCES State (StateID)
)
GO

CREATE TABLE TimeBasis (
	-- Time Basis has value,
	TimeBasisValue                          varchar NOT NULL,
	PRIMARY KEY(TimeBasisValue)
)
GO

CREATE TABLE TravelMethod (
	-- Travel Method has Travel Method Code,
	TravelMethodCode                        varchar(16) NOT NULL,
	PRIMARY KEY(TravelMethodCode)
)
GO

CREATE TABLE [User] (
	-- maybe User was sent confirmation request at Date Time,
	ConfirmationSentAt                      datetime NULL,
	-- maybe User has Confirmation Token,
	ConfirmationToken                       varchar NULL,
	-- maybe User was confirmed at Date Time,
	ConfirmedAt                             datetime NULL,
	-- maybe User is currently signed in at Date Time,
	CurrentSignInAt                         datetime NULL,
	-- maybe User is currently signed in from IP Address,
	CurrentSignInIP                         varchar(32) NULL,
	-- User has EmailAddress,
	Email                                   varchar(80) NOT NULL,
	-- User has Encrypted Password,
	EncryptedPassword                       varchar NOT NULL,
	-- maybe User previously signed in at Date Time,
	LastSignInAt                            datetime NULL,
	-- maybe User previously signed in from IP Address,
	LastSignInIP                            varchar(32) NULL,
	-- User is a kind of Person and Person is a kind of Party and Party has Party ID,
	PersonID                                int NOT NULL,
	-- maybe User is remembered since Date Time,
	RememberCreatedAt                       datetime NULL,
	-- maybe User was sent password recovery token at Date Time,
	ResetPasswordSentAt                     datetime NULL,
	-- maybe User has Reset Password Token,
	ResetPasswordToken                      varchar NULL,
	-- User has sign-- in Count,
	SignInCount                             int NOT NULL,
	-- maybe User has unconfirmed-EmailAddress,
	UnconfirmedEmail                        varchar(80) NULL,
	PRIMARY KEY(PersonID),
	UNIQUE(Email),
	FOREIGN KEY (PersonID) REFERENCES Person (PartyID)
)
GO

CREATE VIEW dbo.User_ResetPasswordToken (ResetPasswordToken) WITH SCHEMABINDING AS
	SELECT ResetPasswordToken FROM dbo.[User]
	WHERE	ResetPasswordToken IS NOT NULL
GO

CREATE UNIQUE CLUSTERED INDEX IX_UserByResetPasswordToken ON dbo.User_ResetPasswordToken(ResetPasswordToken)
GO

CREATE VIEW dbo.User_UnconfirmedEmail (UnconfirmedEmail) WITH SCHEMABINDING AS
	SELECT UnconfirmedEmail FROM dbo.[User]
	WHERE	UnconfirmedEmail IS NOT NULL
GO

CREATE UNIQUE CLUSTERED INDEX IX_UserByUnconfirmedEmail ON dbo.User_UnconfirmedEmail(UnconfirmedEmail)
GO

CREATE TABLE UsersRole (
	-- Users Role (in which User is authorized to act in Role) and Role has ID,
	RoleID                                  int NOT NULL,
	-- Users Role (in which User is authorized to act in Role) and User is a kind of Person and Person is a kind of Party and Party has Party ID,
	UserID                                  int NOT NULL,
	PRIMARY KEY(UserID, RoleID),
	FOREIGN KEY (RoleID) REFERENCES Role (ID),
	FOREIGN KEY (UserID) REFERENCES [User] (PersonID)
)
GO

CREATE TABLE Vacancy (
	-- maybe Vacancy applications close on Date,
	ApplicationClosingDate                  datetime NULL,
	-- maybe Vacancy closes on closing-Date,
	ClosingDate                             datetime NULL,
	-- maybe Vacancy has Contact Role and Contact Role (in which Person is Contact Kind contact for Department) involves Contact Kind,
	ContactRoleContactKind                  varchar(32) NULL,
	-- maybe Vacancy has Contact Role and Contact Role (in which Person is Contact Kind contact for Department) and Department has Department ID,
	ContactRoleDepartmentID                 int NULL,
	-- maybe Vacancy has Contact Role and Contact Role (in which Person is Contact Kind contact for Department) and Person is a kind of Party and Party has Party ID,
	ContactRolePersonID                     int NULL,
	-- Vacancy is with Employer and Employer is a kind of Company and Company is a kind of Party and Party has Party ID,
	EmployerID                              int NOT NULL,
	-- maybe Vacancy must be filled by Date,
	FillByDate                              datetime NULL,
	-- Vacancy is for apprentice,
	IsForApprentice                         bit NULL,
	-- Vacancy is for trainee,
	IsForTrainee                            bit NULL,
	-- maybe Vacancy is described by Job Description,
	JobDescription                          varchar(4000) NULL,
	-- Vacancy is for Job Title and Job Title has Job Title Name,
	JobTitleName                            varchar(60) NOT NULL,
	-- maybe Vacancy is at Location and Location (in which Party has Location Role at Address) and Address is in Country and Country has ISO3166Code3,
	LocationAddressCountryISO3166Code3      varchar(3) NULL,
	-- maybe Vacancy is at Location and Location (in which Party has Location Role at Address) and Address is in State and State has State ID,
	LocationAddressStateID                  int NULL,
	-- maybe Vacancy is at Location and Location (in which Party has Location Role at Address) and Address has Street,
	LocationAddressStreet                   varchar(64) NULL,
	-- maybe Vacancy is at Location and Location (in which Party has Location Role at Address) and Address has Suburb and Suburb has Suburb ID,
	LocationAddressSuburbID                 int NULL,
	-- maybe Vacancy is at Location and Location (in which Party has Location Role at Address) and Party has Party ID,
	LocationPartyID                         int NULL,
	-- maybe Vacancy is at Location and Location (in which Party has Location Role at Address) and Location Role has value,
	LocationRoleValue                       varchar(32) NULL,
	-- Vacancy is for Nr,
	Nr                                      int NOT NULL,
	-- maybe Vacancy starts on opening-Date,
	OpeningDate                             datetime NULL,
	-- maybe Vacancy has Time Basis and Time Basis has value,
	TimeBasisValue                          varchar NULL,
	-- Vacancy has Vacancy ID,
	VacancyID                               int IDENTITY NOT NULL,
	-- Vacancy has Vacancy Status and Vacancy Status has Vacancy Status Code,
	VacancyStatusCode                       varchar(16) NOT NULL,
	PRIMARY KEY(VacancyID),
	FOREIGN KEY (EmployerID) REFERENCES Company (PartyID),
	FOREIGN KEY (ContactRolePersonID, ContactRoleContactKind, ContactRoleDepartmentID) REFERENCES ContactRole (PersonID, ContactKind, DepartmentID),
	FOREIGN KEY (LocationPartyID, LocationRoleValue, LocationAddressStreet, LocationAddressSuburbID, LocationAddressStateID, LocationAddressCountryISO3166Code3) REFERENCES Location (PartyID, LocationRoleValue, AddressStreet, AddressSuburbID, AddressStateID, AddressCountryISO3166Code3),
	FOREIGN KEY (TimeBasisValue) REFERENCES TimeBasis (TimeBasisValue)
)
GO

CREATE TABLE VehicleLicence (
	-- Vehicle Licence (in which Driver has licence of Vehicle Licence Type) and Driver is a kind of Person and Person is a kind of Party and Party has Party ID,
	DriverID                                int NOT NULL,
	-- Vehicle Licence is limited to automatic vehicles,
	IsLimitedToAutomaticVehicles            bit NULL,
	-- maybe Vehicle Licence was obtained on obtained-Date,
	ObtainedDate                            datetime NULL,
	-- maybe Vehicle Licence has remaining-Demerit Points,
	RemainingDemeritPoints                  smallint NULL CHECK((RemainingDemeritPoints >= 0 AND RemainingDemeritPoints <= 20)),
	-- maybe Vehicle Licence has Vehicle Licence Number,
	VehicleLicenceNumber                    varchar(24) NULL,
	-- Vehicle Licence (in which Driver has licence of Vehicle Licence Type) and Vehicle Licence Type has Vehicle Licence Type Name,
	VehicleLicenceTypeName                  varchar(60) NOT NULL,
	PRIMARY KEY(DriverID, VehicleLicenceTypeName),
	FOREIGN KEY (DriverID) REFERENCES Person (PartyID)
)
GO

CREATE TABLE VehicleLicenceType (
	-- Vehicle Licence Type has Vehicle Licence Type Name,
	VehicleLicenceTypeName                  varchar(60) NOT NULL,
	PRIMARY KEY(VehicleLicenceTypeName)
)
GO

CREATE TABLE Widget (
	-- maybe Widget has Widget Path,
	PartialPath                             varchar NULL,
	-- Widget has Widget Name,
	WidgetName                              varchar NOT NULL,
	-- maybe Widget has Widget Title,
	WidgetTitle                             varchar NULL,
	PRIMARY KEY(WidgetName)
)
GO

CREATE TABLE WorkStatus (
	-- Work Status has value,
	WorkStatusValue                         varchar NOT NULL,
	PRIMARY KEY(WorkStatusValue)
)
GO

CREATE TABLE WorkTravelMethod (
	-- Work Travel Method (in which Candidate commutes by Travel Method) and Candidate is a kind of Person and Person is a kind of Party and Party has Party ID,
	CandidateID                             int NOT NULL,
	-- Work Travel Method (in which Candidate commutes by Travel Method) and Travel Method has Travel Method Code,
	TravelMethodCode                        varchar(16) NOT NULL,
	PRIMARY KEY(CandidateID, TravelMethodCode),
	FOREIGN KEY (CandidateID) REFERENCES Candidate (PersonID),
	FOREIGN KEY (TravelMethodCode) REFERENCES TravelMethod (TravelMethodCode)
)
GO

CREATE TABLE Worker (
	-- Worker is a kind of Person and Person is a kind of Party and Party has Party ID,
	PersonID                                int NOT NULL,
	-- Worker has Work Status and Work Status has value,
	WorkStatusValue                         varchar NOT NULL,
	PRIMARY KEY(PersonID),
	FOREIGN KEY (PersonID) REFERENCES Person (PartyID),
	FOREIGN KEY (WorkStatusValue) REFERENCES WorkStatus (WorkStatusValue)
)
GO

ALTER TABLE AllowedResponse
	ADD FOREIGN KEY (QuestionNaireSectionQuestionnaireName, QuestionNaireSectionNr, QuestionSequenceNr) REFERENCES Question (QuestionnaireSectionQuestionnaireName, QuestionnaireSectionNr, SequenceNr)
GO

ALTER TABLE AllowedResponse
	ADD FOREIGN KEY (RoleID) REFERENCES Role (ID)
GO

ALTER TABLE AptitudeTesting
	ADD FOREIGN KEY (CandidateID) REFERENCES Candidate (PersonID)
GO

ALTER TABLE Candidate
	ADD FOREIGN KEY (CandidateStatusValue) REFERENCES CandidateStatus (CandidateStatusValue)
GO

ALTER TABLE Candidate
	ADD FOREIGN KEY (WorkExperienceCompanyID) REFERENCES Company (PartyID)
GO

ALTER TABLE Candidate
	ADD FOREIGN KEY (BirthCountryISO3166Code3) REFERENCES Country (ISO3166Code3)
GO

ALTER TABLE Candidate
	ADD FOREIGN KEY (PrimarycitizenshipCountryISO3166Code3) REFERENCES Country (ISO3166Code3)
GO

ALTER TABLE Candidate
	ADD FOREIGN KEY (ResumeDocumentID) REFERENCES Document (DocumentID)
GO

ALTER TABLE Candidate
	ADD FOREIGN KEY (WorkExperienceContactPersonID) REFERENCES Person (PartyID)
GO

ALTER TABLE Candidate
	ADD FOREIGN KEY (PersonID) REFERENCES Person (PartyID)
GO

ALTER TABLE Candidate
	ADD FOREIGN KEY (SchoolAttendanceSuburbID) REFERENCES Suburb (SuburbID)
GO

ALTER TABLE CandidateReferral
	ADD FOREIGN KEY (ReferralName) REFERENCES Referral (ReferralName)
GO

ALTER TABLE Company
	ADD FOREIGN KEY (PartyID) REFERENCES Party (PartyID)
GO

ALTER TABLE Contact
	ADD FOREIGN KEY (ContactMethodName) REFERENCES ContactMethod (ContactMethodName)
GO

ALTER TABLE Contact
	ADD FOREIGN KEY (ContactTypeName) REFERENCES ContactType (ContactTypeName)
GO

ALTER TABLE Contact
	ADD FOREIGN KEY (ContactReportFileNoteID) REFERENCES FileNote (FileNoteID)
GO

ALTER TABLE Contact
	ADD FOREIGN KEY (PartyID) REFERENCES Party (PartyID)
GO

ALTER TABLE Contact
	ADD FOREIGN KEY (BookedforPersonID) REFERENCES Person (PartyID)
GO

ALTER TABLE Contact
	ADD FOREIGN KEY (ContacterID) REFERENCES Person (PartyID)
GO

ALTER TABLE Contact
	ADD FOREIGN KEY (ContactReportPlacementWorkerID, ContactReportPlacementVacancyID) REFERENCES Placement (WorkerID, VacancyID)
GO

ALTER TABLE Contact
	ADD FOREIGN KEY (ScheduledContactScheduleName, ScheduledContactIntervalCount, ScheduledContactIntervalContactPeriod) REFERENCES ScheduledContact (ContactScheduleName, ContactIntervalCount, ContactIntervalContactPeriod)
GO

ALTER TABLE Contact
	ADD FOREIGN KEY (ContactReportCompletedbyUserID) REFERENCES [User] (PersonID)
GO

ALTER TABLE ContactResponse
	ADD FOREIGN KEY (QuestionNaireSectionQuestionnaireName, QuestionNaireSectionNr, QuestionSequenceNr) REFERENCES Question (QuestionnaireSectionQuestionnaireName, QuestionnaireSectionNr, SequenceNr)
GO

ALTER TABLE ContactRole
	ADD FOREIGN KEY (DepartmentID) REFERENCES Department (DepartmentID)
GO

ALTER TABLE ContactRole
	ADD FOREIGN KEY (PersonID) REFERENCES Person (PartyID)
GO

ALTER TABLE ContactSignature
	ADD FOREIGN KEY (OnBehalfOfID) REFERENCES Party (PartyID)
GO

ALTER TABLE ContactSignature
	ADD FOREIGN KEY (PersonID) REFERENCES Person (PartyID)
GO

ALTER TABLE Correspondence
	ADD FOREIGN KEY (CorrespondenceMethodName) REFERENCES CorrespondenceMethod (CorrespondenceMethodName)
GO

ALTER TABLE Correspondence
	ADD FOREIGN KEY (ReceivedDocumentID) REFERENCES Document (DocumentID)
GO

ALTER TABLE Correspondence
	ADD FOREIGN KEY (SentDocumentID) REFERENCES Document (DocumentID)
GO

ALTER TABLE Correspondence
	ADD FOREIGN KEY (PartyID) REFERENCES Party (PartyID)
GO

ALTER TABLE Correspondence
	ADD FOREIGN KEY (StaffMemberID) REFERENCES Person (PartyID)
GO

ALTER TABLE DashboardWidget
	ADD FOREIGN KEY (DashboardUserID) REFERENCES [User] (PersonID)
GO

ALTER TABLE DashboardWidget
	ADD FOREIGN KEY (WidgetName) REFERENCES Widget (WidgetName)
GO

ALTER TABLE Document
	ADD FOREIGN KEY (DocumentFormatCode) REFERENCES DocumentFormat (DocumentFormatCode)
GO

ALTER TABLE Document
	ADD FOREIGN KEY (PersonID) REFERENCES Person (PartyID)
GO

ALTER TABLE Employment
	ADD FOREIGN KEY (WorksiteLocationPartyID, WorksiteLocationRoleValue, WorksiteLocationAddressStreet, WorksiteLocationAddressSuburbID, WorksiteLocationAddressStateID, WorksiteLocationAddressCountryISO3166Code3) REFERENCES Location (PartyID, LocationRoleValue, AddressStreet, AddressSuburbID, AddressStateID, AddressCountryISO3166Code3)
GO

ALTER TABLE Employment
	ADD FOREIGN KEY (EmployeeID) REFERENCES Person (PartyID)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (FileNoteTemplateName) REFERENCES FileNoteTemplate (FileNoteTemplateName)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (FileNoteTypeValue) REFERENCES FileNoteType (FileNoteTypeValue)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (InterviewCandidateID, InterviewEmployerID, InterviewDateMaybeTimeDate, InterviewDateMaybeTime) REFERENCES Interview (CandidateID, EmployerID, DateMaybeTimeDate, DateMaybeTime)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (PersonID) REFERENCES Person (PartyID)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (ReferenceCheckPersonalReferenceCandidateID, ReferenceCheckPersonalReferencePreviousEmployerCompanyName, ReferenceCheckPersonalReferenceRefereeName) REFERENCES PersonalReference (CandidateID, PreviousEmployerCompanyName, RefereeName)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (PlacementApplicationPersonID, PlacementApplicationVacancyID) REFERENCES PlacementApplication (PersonID, VacancyID)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (PreviousEmploymentCandidateID, PreviousEmploymentPreviousEmployerCompanyName) REFERENCES PreviousEmployment (CandidateID, PreviousEmployerCompanyName)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (CompletedbyUserID) REFERENCES [User] (PersonID)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (FollowupUserID) REFERENCES [User] (PersonID)
GO

ALTER TABLE FileNote
	ADD FOREIGN KEY (VacancyID) REFERENCES Vacancy (VacancyID)
GO

ALTER TABLE FileNoteTemplate
	ADD FOREIGN KEY (FollowupUserID) REFERENCES [User] (PersonID)
GO

ALTER TABLE Filter
	ADD FOREIGN KEY (SearchID) REFERENCES Search (SearchID)
GO

ALTER TABLE Filter
	ADD FOREIGN KEY (SearchFacetID) REFERENCES SearchFacet (SearchFacetID)
GO

ALTER TABLE Interview
	ADD FOREIGN KEY (PersonID) REFERENCES Person (PartyID)
GO

ALTER TABLE Interview
	ADD FOREIGN KEY (PlacementApplicationPersonID, PlacementApplicationVacancyID) REFERENCES PlacementApplication (PersonID, VacancyID)
GO

ALTER TABLE Location
	ADD FOREIGN KEY (LocationRoleValue) REFERENCES LocationRole (LocationRoleValue)
GO

ALTER TABLE Location
	ADD FOREIGN KEY (PartyID) REFERENCES Party (PartyID)
GO

ALTER TABLE Location
	ADD FOREIGN KEY (AddressStateID) REFERENCES State (StateID)
GO

ALTER TABLE Location
	ADD FOREIGN KEY (AddressSuburbID) REFERENCES Suburb (SuburbID)
GO

ALTER TABLE PartyPhone
	ADD FOREIGN KEY (PhoneRoleValue) REFERENCES PhoneRole (PhoneRoleValue)
GO

ALTER TABLE PartyPreference
	ADD FOREIGN KEY (SettablePreferenceName) REFERENCES SettablePreference (SettablePreferenceName)
GO

ALTER TABLE Person
	ADD FOREIGN KEY (SalutationCode) REFERENCES Salutation (SalutationCode)
GO

ALTER TABLE PersonalCharacterisation
	ADD FOREIGN KEY (PersonalCharacteristicName) REFERENCES PersonalCharacteristic (PersonalCharacteristicName)
GO

ALTER TABLE Placement
	ADD FOREIGN KEY (VacancyID) REFERENCES Vacancy (VacancyID)
GO

ALTER TABLE Placement
	ADD FOREIGN KEY (WorkerID) REFERENCES Worker (PersonID)
GO

ALTER TABLE PlacementApplication
	ADD FOREIGN KEY (VacancyID) REFERENCES Vacancy (VacancyID)
GO

ALTER TABLE Question
	ADD FOREIGN KEY (QuestionnaireSectionQuestionnaireName, QuestionnaireSectionNr) REFERENCES QuestionnaireSection (QuestionnaireName, SectionNr)
GO

ALTER TABLE Search
	ADD FOREIGN KEY (UserID) REFERENCES [User] (PersonID)
GO

ALTER TABLE SkillsCertificate
	ADD FOREIGN KEY (SkillsCertificationName) REFERENCES SkillsCertification (SkillsCertificationName)
GO

ALTER TABLE VehicleLicence
	ADD FOREIGN KEY (VehicleLicenceTypeName) REFERENCES VehicleLicenceType (VehicleLicenceTypeName)
GO