Assignment - Database Developer Outcome/Task/Result - Build a candidate management…
- User
Assignment - Database Developer Outcome/Task/Result - Build a candidate management database schema using MYSQL OR MSSQL only. The schema contains three primary entities - ● Account ● User ● Candidate Account entity contains following fields: Column Name Description ID Unique id per Account Title Name of the Account Candidates Created count Count of candidates created on Account Candidates Deleted count Count of candidates created on Account User entity contains following fields: Column Name Description ID Unique id per User record First Name First Name of User Last Name Last Name of User Email Id Email Address of User AccountID AccountID of the User Candidates Created count Count of candidates created by User Candidates Deleted count Count of candidates created by User Candidate entity has following fields: Field Description ID Unique id per candidate record Serial Number Unique sequence number (serial number) per account. First Name First Name of candidate Last Name Last Name of candidate Email Address Email Address of candidate Gender Id Gender id of candidate Contact number Contact number of candidate(can be multiple using comma) Qualification Id Qualification id of the candidate Date of Birth Date of birth Resume File Link Link of the Resume File Resume text Extracted text from resume. Should be searchable and quick. Resume File name Resume File name Willing to relocate Does the candidate wish to relocate? 0 - no, 1 -yes Slug Unique string(can be used to mask id in urls) Linked In Url Linkedin profile url AccountID AccountID of Candidate record Created By User Id User id who has created the record Created On Time when record was created Address Full address of candidate Latitude Latitude Longitude Longitude Skills One candidate can have multiple skills Instructions & Guidelines to create the database schema in mysql that satisfies following conditions: ● Design and create tables with suitable columns, data types and normalisation. Ensure appropriate relationships, such as one-to-one, one-to-many, and many-to-many, are maintained. If necessary, create additional tables. ● Implement reference tables with relevant values for the dependent fields (shown in yellow). ● Incorporate indexes on columns that are frequently used in search or join operations. Identify the columns that are commonly queried or involved in joins, and create indexes to optimise query performance. ● Utilize triggers, procedures, views and functions where necessary to enhance functionality and maintain scalability. Document these database objects, including their purpose, input parameters, and expected output. ● Develop and implement a logging mechanism to track and record changes made to candidate records. ● Share .sql dump file while submitting the assignment. (mandatory) Assignment Tasks: Task 1: a. Document the logging mechanism, including the structure of the log table, the logged events and the information captured in the logs. b. Create comprehensive documentation for the database schema, including table definitions, column descriptions, relationships, and indexes. Document any naming conventions, data constraints, and data types used throughout the schema. c. Document any specific design decisions, such as the reasoning behind the choice of normalisation levels, table structures and relationships. (Note : You need to write the documentation along with queries, tables etc. for a, b & c to get maximum scores) Task 2: a. Write a query to delete the User record.(Mandatory) b. Write a query to search candidates based on name, email and linkedIn URLs. c. Write an optimized boolean search query to fetch candidate records using resumetext. d. Write a query to fetch comma separated User IDs against each account title. e. Write a query to fetch counts of Candidates, based on gender, on each account.
- Assistant
- User
Provide Database Schema Queries for creating the Schema and Tables ?
- Assistant
Sure! Here are the queries to create the database schema and tables:
-- Create Account table CREATE TABLE Account ( ID INT NOT NULL PRIMARY KEY, Title VARCHAR(255), CandidatesCreatedCount INT, CandidatesDeletedCount INT ); -- Create User table CREATE TABLE User ( ID INT NOT NULL PRIMARY KEY, FirstName VARCHAR(255), LastName VARCHAR(255), EmailId VARCHAR(255), AccountID INT, CandidatesCreatedCount INT, CandidatesDeletedCount INT, FOREIGN KEY (AccountID) REFERENCES Account(ID) ); -- Create Candidate table CREATE TABLE Candidate ( ID INT NOT NULL PRIMARY KEY, SerialNumber INT, FirstName VARCHAR(255), LastName VARCHAR(255), EmailAddress VARCHAR(255), GenderId INT, ContactNumber VARCHAR(255), QualificationId INT, DateOfBirth DATE, ResumeFileLink VARCHAR(255), ResumeText TEXT, ResumeFileName VARCHAR(255), WillingToRelocate TINYINT, Slug VARCHAR(255), LinkedInUrl VARCHAR(255), AccountID INT, CreatedByUserId INT, CreatedOn DATETIME, Address VARCHAR(255), Latitude DECIMAL(9,6), Longitude DECIMAL(9,6), Skills VARCHAR(255), FOREIGN KEY (AccountID) REFERENCES Account(ID), FOREIGN KEY (CreatedByUserId) REFERENCES User(ID) ); - User
create a schema named Assignment for the above ?
- Assistant
Sure! Here's the query to create a schema named "Assignment" and the tables within the schema:
-- Create Assignment schema CREATE SCHEMA Assignment; -- Switch to Assignment schema USE Assignment; -- Create Account table CREATE TABLE Account ( ID INT NOT NULL PRIMARY KEY, Title VARCHAR(255), CandidatesCreatedCount INT, CandidatesDeletedCount INT ); -- Create User table CREATE TABLE User ( ID INT NOT NULL PRIMARY KEY, FirstName VARCHAR(255), LastName VARCHAR(255), EmailId VARCHAR(255), AccountID INT, CandidatesCreatedCount INT, CandidatesDeletedCount INT, FOREIGN KEY (AccountID) REFERENCES Account(ID) ); -- Create Candidate table CREATE TABLE Candidate ( ID INT NOT NULL PRIMARY KEY, SerialNumber INT, FirstName VARCHAR(255), LastName VARCHAR(255), EmailAddress VARCHAR(255), GenderId INT, ContactNumber VARCHAR(255), QualificationId INT, DateOfBirth DATE, ResumeFileLink VARCHAR(255), ResumeText TEXT, ResumeFileName VARCHAR(255), WillingToRelocate TINYINT, Slug VARCHAR(255), LinkedInUrl VARCHAR(255), AccountID INT, CreatedByUserId INT, CreatedOn DATETIME, Address VARCHAR(255), Latitude DECIMAL(9,6), Longitude DECIMAL(9,6), Skills VARCHAR(255), FOREIGN KEY (AccountID) REFERENCES Account(ID), FOREIGN KEY (CreatedByUserId) REFERENCES User(ID) ); - User
Provide the Log table queries ?
- Assistant
Here's the query to create the Log table within the Assignment schema:
-- Switch to Assignment schema USE Assignment; -- Create Log table CREATE TABLE Log ( ID INT NOT NULL PRIMARY KEY, Event VARCHAR(255), EventDescription VARCHAR(255), Timestamp DATETIME, UserID INT, CandidateID INT, FOREIGN KEY (UserID) REFERENCES User(ID), FOREIGN KEY (CandidateID) REFERENCES Candidate(ID) );The Log table has columns for ID (unique id per log record), Event (type of event - create, update, delete), EventDescription (description of the event), Timestamp (time when the event occurred), UserID (ID of the user who performed the event), and CandidateID (ID of the candidate affected by the event).
- User
Queries for creating Skills and Candidate skills table for the above ?
- Assistant
Sure! Here are the queries to create the Skills and CandidateSkills tables:
-- Switch to Assignment schema USE Assignment; -- Create Skills table CREATE TABLE Skills ( ID INT NOT NULL PRIMARY KEY, SkillName VARCHAR(255) ); -- Create CandidateSkills table CREATE TABLE CandidateSkills ( CandidateID INT, SkillID INT, PRIMARY KEY (CandidateID, SkillID), FOREIGN KEY (CandidateID) REFERENCES Candidate(ID), FOREIGN KEY (SkillID) REFERENCES Skills(ID) );The Skills table has columns for ID (unique id per skill) and SkillName (name of the skill).
The CandidateSkills table serves as an intermediate table to establish a many-to-many relationship between Candidates and Skills. It has columns for CandidateID and SkillID, which act as foreign keys referencing the Candidate and Skills tables respectively. The primary key of the CandidateSkills table is a composite key consisting of both CandidateID and SkillID.
- User
What value will the Skills column hold in Candidate table ?
- Assistant
In the Candidate table, the Skills column will hold a comma-separated list of skill IDs or skill names associated with the candidate. Each skill will be represented by its corresponding ID or name. For example, if a candidate has skills with IDs 1, 3, and 5, the Skills column may contain a value like "1,3,5" or "Java,JavaScript,Python".
It is worth noting that using a comma-separated list in a single column like this can lead to difficulties in querying and maintaining data integrity. Alternatively, a separate table (such as the Skills table mentioned earlier) can be used to store individual skill records, and a junction table (such as the CandidateSkills table mentioned earlier) can be used to establish the many-to-many relationship between Candidates and Skills. This approach allows for better data organization, easier querying, and improved data integrity.
- User
Trigger queries for logging all events in Log table on every Operation ?
- Assistant
To log all events in the Log table on every operation (create, update, delete) performed on the Candidate and User tables, you can use triggers in your database. Here are the trigger queries:
For Candidate table:
-- Create trigger for candidate creation CREATE TRIGGER candidate_create_trigger AFTER INSERT ON Candidate FOR EACH ROW BEGIN INSERT INTO Log (Event, EventDescription, Timestamp, UserID, CandidateID) VALUES ('Create Candidate', 'Candidate created', NOW(), NEW.CreatedByUserId, NEW.ID); END; -- Create trigger for candidate update CREATE TRIGGER candidate_update_trigger AFTER UPDATE ON Candidate FOR EACH ROW BEGIN INSERT INTO Log (Event, EventDescription, Timestamp, UserID, CandidateID) VALUES ('Update Candidate', 'Candidate updated', NOW(), NEW.CreatedByUserId, NEW.ID); END; -- Create trigger for candidate deletion CREATE TRIGGER candidate_delete_trigger AFTER DELETE ON Candidate FOR EACH ROW BEGIN INSERT INTO Log (Event, EventDescription, Timestamp, UserID, CandidateID) VALUES ('Delete Candidate', 'Candidate deleted', NOW(), OLD.CreatedByUserId, OLD.ID); END; - User
Candidate table along with its trigger for log audit above queries together ?
- Assistant
Certainly! Here's the modified query that includes the creation of the Candidate table along with the triggers for logging events:
-- Switch to Assignment schema USE Assignment; -- Create Candidate table CREATE TABLE Candidate ( ID INT NOT NULL PRIMARY KEY, SerialNumber INT, FirstName VARCHAR(255), LastName VARCHAR(255), EmailAddress VARCHAR(255), GenderId INT, ContactNumber VARCHAR(255), QualificationId INT, DateOfBirth DATE, ResumeFileLink VARCHAR(255), ResumeText TEXT, ResumeFileName VARCHAR(255), WillingToRelocate TINYINT, Slug VARCHAR(255), LinkedInUrl VARCHAR(255), AccountID INT, CreatedByUserId INT, CreatedOn DATETIME, Address VARCHAR(255), Latitude DECIMAL(9,6), Longitude DECIMAL(9,6), Skills VARCHAR(255), FOREIGN KEY (AccountID) REFERENCES Account(ID), FOREIGN KEY (CreatedByUserId) REFERENCES User(ID) ); -- Create trigger for candidate creation CREATE TRIGGER candidate_create_trigger AFTER INSERT ON Candidate FOR EACH ROW BEGIN INSERT INTO Log (Event, EventDescription, Timestamp, UserID, CandidateID) VALUES ('Create Candidate', 'Candidate created', NOW(), NEW.CreatedByUserId, NEW.ID); END; -- Create trigger for candidate update CREATE TRIGGER candidate_update_trigger AFTER UPDATE ON Candidate FOR EACH ROW BEGIN INSERT INTO Log (Event, EventDescription, Timestamp, UserID, CandidateID) VALUES ('Update Candidate', 'Candidate updated', NOW(), NEW.CreatedByUserId, NEW.ID); END; -- Create trigger for candidate deletion CREATE TRIGGER candidate_delete_trigger AFTER DELETE ON Candidate FOR EACH ROW BEGIN INSERT INTO Log (Event, EventDescription, Timestamp, UserID, CandidateID) VALUES ('Delete Candidate', 'Candidate deleted', NOW(), OLD.CreatedByUserId, OLD.ID); END;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.