Question

In: Computer Science

Design a simple database to track people and who they voted for. The database should have...

Design a simple database to track people and who they voted for. The database should have 3 tables:

A table of candidates
A table of registered voters
A table of votes
The candidate table should provide a listing of all candidates and information about the candidates.
The registered voter table should hold all registered voters and any pertinent information about them
The vote table should hold vote records for each candidate made by the voters

Requirements:

The system should not allow duplicate voters to be added to the registered voter table based on a voter_id number field
The system should reject duplicate votes by the same voter
Pick the relevant fields needed for each table to make the system useful
Provide:

SQL code to create the three tables
SQL code to insert test data into the database
A SQL query to retrieve the vote of record of a particular individual

Solutions

Expert Solution

1.Table Name :candidates
create table candidates(
candidateID int Primary key,
candidateName varchar(100),
netWorth decimal(10,2),
DOB date,
Mobile varchar(10));

/*inserting records into candidates table*/
insert into candidates values (1,'Sam Ram',2356987,'1986/05/12','8855663322');
insert into candidates values (2,'Mr.Loko',78963,'1976/09/10','4567891230');
insert into candidates values (3,'RG Sons',12345,'1982/01/30','1234567890');

/*selecting records*/
select * from candidates

Screen showing records :

***********************************************

2.Table Name :registeredVoters
create table registeredVoters(
registeredVoterID int Primary key,
registeredVoterName varchar(100),
DOB date,
Mobile varchar(10),
address varchar(500),
zipCode int(6));

/*inserting records into registeredVoters table*/
insert into registeredVoters values (1,'Voter1','1999/03/31','1245698707','NY',789456);
insert into registeredVoters values (2,'Voter2','2001/04/29','8888888888','UK',456123);
insert into registeredVoters values (3,'Voter3','1992/11/30','5566887799','US',123456);

/*selecting records*/
select * from registeredVoters;'

Screen showing records :

******************************************

3.Table Name :votes
create table votes(
registeredVoterID int ,
candidateID int,
VotingDate date,
ElectionType varchar(50),
Primary key(registeredVoterID,candidateID,VotingDate),
foreign key (registeredVoterID) references registeredVoters(registeredVoterID),
foreign key (candidateID) references candidates(candidateID));

/*inserting records into votes table*/
insert into votes values (1,1,'2020/10/03','MP');
insert into votes values (2,2,'2020/10/03','MP');
insert into votes values (3,3,'2020/10/03','MP');


/*selecting records*/
select * from votes;

Screen showing records :

***********************************

A SQL query to retrieve the vote of record of a particular individual :

select registeredVoters.registeredVoterID,registeredVoterName,
candidates.candidateID,candidateName,VotingDate
from
registeredVoters inner join votes
   on registeredVoters.registeredVoterID=votes.registeredVoterID
inner join candidates
   on votes.candidateID=candidates.candidateID;

Query result :


Related Solutions

Design a database through the EER diagram to keep track of the teams and games of...
Design a database through the EER diagram to keep track of the teams and games of a sport league. Assume that the following requirements are collected (the English description of cardinal ration and partial/complete participate is NOT required, but you still need to provide the total/partial and cardino ration in your EER diagram) : The database has a collection of TEAM. Each Team has a unique name, players, and owner. The database also keeps the records of PLAYERS. Each player...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
A loan company wants to design a database to track student loans. Each student attending school...
A loan company wants to design a database to track student loans. Each student attending school is eligible for a loan. A student may have more than one loan. A student may be registered, possibly at different times, in more than one school. Each loan should belong to only one bank. Each bank can approve as many loans as it desires. For each loan, the loan company will track: the student’s SSN, name, address, amount of loan, date of the...
A loan company wants to design a database to track student loans. Each student attending school...
A loan company wants to design a database to track student loans. Each student attending school is eligible for a loan. A student may have more than one loan. A student may be registered, possibly at different times, in more than one school. Each loan should belong to only one bank. Each bank can approve as many loans as it desires. For each loan, the loan company will track: the student’s SSN, name, address, amount of loan, date of the...
Who should provide aid (such as housing) to people who have been devastated by a major...
Who should provide aid (such as housing) to people who have been devastated by a major natural or man-made disaster? The federal government, the local government, private organizations, or the victims themselves? Why? Please use 3 of Elements of critical thinking from Holistic Critical Thinking Scoring Rubric (Facione & Gittens, 2016) to support your rationale/argument: Accurately interprets evidence, statements, graphics,questions, etc Identifies the salient arguments’(reasons and claims) pros and cons. Thoughtfully analyzes and evaluates major alternative points of view. Draws...
You are asked to design a relational database for a simple course registration software application for...
You are asked to design a relational database for a simple course registration software application for your school. The relational database must have the following information about the student, the course, and the registration, respectively StudentID, FirstName, LastName, DataOfJoining, and Major CourseNumber, CourseName,InstructorName, StartDate, EndDate, NumberOfCredits ReferenceID, StudentID,CourseID, DateOfRegistration Apply the following constrains while designing the database Each student in the database must be uniquely identifiable Each course listed in the database must be have unique CourseNumber Each course registration...
Database Design and SQL The following relations keep track of airline flight information: Flights (flno: integer,...
Database Design and SQL The following relations keep track of airline flight information: Flights (flno: integer, from : string, to: string, distance: integer, departs: time, arrive: time, price: integer) Aircraft (aid: integer, aname : string, cruisingrange: integer) Certified (eid: integer, aid: integer) Employees (eid: integer, ename : string, salary: integer) The Employees relation describe pilots and other kinds of employees as well. Every pilot is certified for some aircraft and only pilots are certified to fly. Based on the schemas,...
Database __________ which is the logical design of the database, and the database _______ which is...
Database __________ which is the logical design of the database, and the database _______ which is a snapshot of the data in the database at a given instant in time. a) Instance, Schema b) Relation, Schema c) Relation, Domain d) Schema, Instance
Describe a simple database of your choice or design, along with the table/s representing the data,...
Describe a simple database of your choice or design, along with the table/s representing the data, and illustrate the Insertion Anomaly through the real data or records there. Your database should be different from those already covered in the lectures or practicals.
Politics. If 12509 people voted for a politician in his first​ election, 14473 voted for him...
Politics. If 12509 people voted for a politician in his first​ election, 14473 voted for him in his second​ election, and 6752 voted for him in the first and second​ elections, how many people voted for this politician in the first or second​ election?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT