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...
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...
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...
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?
Database You have just started a new position on the database design staff at Gizmonic Consultants,...
Database You have just started a new position on the database design staff at Gizmonic Consultants, Inc. Your first project is to translate the database requirements for Continental Hotels into an ER representation. In the next project, you will derive a relational schema from an ER diagram and implement the schema, populate it, and query over it. Requirements: Develop an ERD to capture the entities and relationships specified in the requirements documentation below. Use only the conventions covered in class....
True or False: Logical database design is the process of modifying the physical database design to...
True or False: Logical database design is the process of modifying the physical database design to improve performance. The two major logical database design techniques are conversion of E-R diagrams to relational tables and data normalization. Multivalued attributes are not permitted in unnormalized data. A many-to-many binary relationship in an E-R diagram requires the creation of a total of three tables in a relational database. A one-to-one unary relationship in an E-R diagram requires the creation of a total of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT