Greetings again experts,
I have four tables, Elections ,Positions, CandidatePositions, Candidates.
The following is the DDL:
Elections - Table
ElectionId int PK, auto increment
ElectionName nvarchar(50)
StartDate datetime
ClosingDate datetime
Positions - Table
PositionId int PK auto increment
ElectionId int (FK to Elections table)
Position nvarchar(50) (example positions, President, VP, Secretary, etc)
Candidates - Table
CandidateID int PK auto increment
CandidateName nvarchar(50)
CurrentOfficeHolder nvarchar(50) (If current office holder, then value is incumbent, otherwise, null)
CandidatePosition - Table
CandidatePositionId int PK auto increment
CandidateId int (FK to Candidates table)
PositionId int (FK to to Positions table
I think the design concept is solid.
The way, we have set up the web design is that there is a dropdown list of all the Election names that stored on our database.
Then, an admin managing the back office would select election name, say Presidential Election, from this dynamically populated dropdown list of all Election Names that are stored on the DB.
Depending on the Admin's selection, we would like the positions associated with that election name to be inserted into the database, along with the election ID.
For instance, if a user selects Presidential Election from the dropdown list, we would like to insert into Positions table President, Vice President under the Position column name of the Positions table.
Any ideas how to Format the insert statement?
Example if we have Elections table with following values:
ElectionID ElectionName
1 Presidential Election
An who is creating an E-Ballot,
inserts the positions of President, Vice President associated with Presidential Election, when we do a join between Elections table and Positions table, we would like to see:
Position Id Election ID Position
1 1 President
2 1 Vice President
I guess my question is do I have to perform two separate inserts statements, one for President and another for Vice President or is there a way to just perform one insert statement to get both values?
I hope I didn't confuse you good people and many thanks in advance