- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnlineVotingJava_SQL.sql
More file actions
Latest commit
103 lines (86 loc) · 2.32 KB
/
Copy pathOnlineVotingJava_SQL.sql
File metadata and controls
103 lines (86 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
createdatabaseonlinevoting;
use onlinevoting;
createtableuser (username varchar(20) primary key,
password varchar(20) not null,
role varchar(20) not null);
ALTERTABLE user
ADD COLUMN name VARCHAR(20) NOT NULL,
ADD COLUMN phone VARCHAR(20) NOT NULL,
ADD COLUMN dob DATENOT NULL,
ADD COLUMN email VARCHAR(50) NOT NULL,
ADD COLUMN id varchar(20) NOT NULL;
ALTERTABLE user
DROP PRIMARY KEY,
ADD PRIMARY KEY (id);
desc user;
altertable user drop column username;
select*from user;
createtableelection (electid varchar(20) primary key,
name varchar(20) not null);
DELIMITER //
CREATETRIGGERUpdateCandidateOrVoter
AFTER INSERT ON User
FOR EACH ROW
BEGIN
IF NEW.role='Candidate' THEN
INSERT INTO Candidate (CandidateID) VALUES (NEW.id);
ELSEIF NEW.role='Voter' THEN
INSERT INTO Voter (VoterID) VALUES (NEW.id);
END IF;
END//
DELIMITER ;
createtableCadidate(CandidateID varchar(20) Primary Key,electionid varchar(10),status varchar(5));
Rename table Cadidate to Candidate;
createtableVoter(VoterID varchar(20) Primary Key,electionid varchar(10),status varchar(5));
select*from voter;
select*from candidate;
select*from user;
select*from election;
desc candidate;
ALTERTABLE election RENAME COLUMN electid TO electionid;
ALTERTABLE election Add COLUMN status varchar(20);
ALTERTABLE election MODIFY COLUMN status varchar(20) DEFAULT "Running";
UPDATE election SET status ="Running";
UPDATE election SET status ='Running'where electionid="Test001706";
DELIMITER //
CREATETRIGGERUpdateCandidateStatus
AFTER UPDATEON Candidate
FOR EACH ROW
BEGIN
IF NEW.electionid!=null THEN
UPDATE Candidate set status="Pending";
END IF;
END//
DELIMITER ;
DELIMITER //
CREATETRIGGERUpdateVoterStatus
AFTER UPDATEON Voter
FOR EACH ROW
BEGIN
IF NEW.electionid!=null THEN
UPDATE Voter set status="P";
END IF;
END//
DELIMITER ;
DropTrigger UpdateVoterStatus;
DropTrigger UpdateCandidateStatus;
DELIMITER //
CREATETRIGGERUpdateVoterStatus
AFTER UPDATEON Voter
FOR EACH ROW
BEGIN
IF NEW.electionid!=null THEN
UPDATE Voter set status="P";
END IF;
END//
DELIMITER ;
DELIMITER //
CREATETRIGGERUpdateCandidateStatus
AFTER UPDATEON Candidate
FOR EACH ROW
BEGIN
IF NEW.electionid!=null THEN
UPDATE Candidate set status="P";
END IF;
END//
DELIMITER ;