β”€β”€β”€βœ±*.q:q✱*.:q✧*.q✰*.:q✧*.q:q*.q✱ ───

Views

CrewRosterView

  • Displays current ship assignments of personnel
  • Joins PERSONNEL, ASSIGNMENT, and STARSHIP
  • Includes name, rank, position, home planet, starship name
  • Filtering for active assignments was intended, but there wasn’t a STATUS column, so it was left commented out (since I didn’t see a way to filter active assignments)

FleetStatusView

  • Monitors ship deployment and crew levels
  • Joins STARSHIP and ASSIGNMENT
  • Includes registry, class, mission, location, crew count, commission date, ship age
  • Order by was skipped since SQL Server has limitations on ordering with views.
    • You have to use either a TOP, OFFSET, or FOR XML clause

MissionHistoryView

  • Tracks visits made by ships to planets
  • Joins VISIT, STARSHIP, and PLANET
  • Includes arrival/depart dates, duration (or β€œCurrently Docked”), and planet attributes

QualificationMatrixView

  • Shows personnel qualifications and experience
  • Joins PERSONNEL and QUAL
  • Calculates the years of experience based on the qualification GRANTED column

Stored Procedures

TransferCrewMember

  • Reassigns a crew member to a new ship and position
  • Verifies existence β†’ deletes old assignment β†’ inserts a new one
  • Handles errors with TRY...CATCH, ROLLBACK, and THROW

RecordPlanetaryVisit

  • Records or updates planetary visits for ships
  • Checks ship and planet exist as well as the arrival being before the departure
  • Updates existing visits or inserts a new row if there isn’t a current visit

MissionResourceAllocation

  • Calculates needed resources for missions
  • Uses a temporary table #ResourcePlan to hold projections
  • Inputs are derived from STARSHIP, MISSION, and TYPE
  • Outputs energy, food, and medical supplies by crew size and priority

Functions

CalculateServiceDuration

  • Returns time between first assignment and a reference date
  • Returns a formatted string such as '3 years, 4 months'
  • If ASSIGNED is null, it defaults to the current date.
    • Since it doesn’t allow for GETDATE() as a default value, there’s a simple check

GetQualifiedPersonnel

  • Lists personnel with a given skill and experience threshold
  • Returns ID, name, rank, planet, years of experience, and current assignment (if any)

Design Decisions/Challenges

  • I wasn’t able to use ORDER BY in views since SQL Server requires TOP, OFFSET, or XML FOR.
  • There was no STATUS column in ASSIGNMENT, so I wasn’t able to filter active assignments
  • Since I wasn’t able to use GETDATE() as a default value, I had to use an IF check and redirect the logic slightly

Performance Considerations

  • Indexed views weren’t used due to joins and aggregates, but they could be optimized if needed
  • MissionHistoryView is lightweight; QualificationMatrixView uses joins for efficiency
  • DELETE + INSERT in TransferCrewMember avoids complex updating of data
  • #ResourcePlan is temporary to minimize permanent clutter within the database

Examples

The example output isn't based on actual data within the database

CrewRosterView

SELECT * FROM CrewRosterView WHERE STARSHIP_NAME = 'USS Voyager';
 
-- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
-- β”‚ PERSONNEL_NAME β”‚ RANK β”‚ POSITION       β”‚ HOME_PLANET β”‚ STARSHIP_NAME β”‚
-- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-- β”‚ Tuvok          β”‚ Ltnt β”‚ Security Chief β”‚ Vulcan      β”‚ USS Voyager   β”‚
-- β”‚ Riker          β”‚ LtCm β”‚ Chief Engineer β”‚ Kessik IV   β”‚ USS Voyager   β”‚
-- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

CalculateServiceDuration

SELECT dbo.CalculateServiceDuration('P0001'); -- '5 years, 3 months'

GetQualifiedPersonnel

SELECT * FROM dbo.GetQualifiedPersonnel('Astrophysics', 3);
 
-- β”Œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
-- β”‚ ID    β”‚ NAME         β”‚ RANK β”‚ PLANET β”‚ YearsOfExperience β”‚ SHIP      β”‚ POSITION       β”‚ ASSIGNED   β”‚
-- β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-- β”‚ P0001 β”‚ Spock        β”‚ Cmdr β”‚ Vulcan β”‚ 5                 β”‚ NCC-1701  β”‚ Science Officerβ”‚ 2370-01-01 β”‚
-- β”‚ P0004 β”‚ Saavik       β”‚ Ltnt β”‚ Romulusβ”‚ 4                 β”‚ NCC-1702  β”‚ Astrophysicist β”‚ 2371-05-01 β”‚
-- β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

TransferCrewMember

EXEC TransferCrewMember 'P0002', 'NCC-1701', 'Tactical Officer', '2373-07-15';

MissionResourceAllocation

EXEC MissionResourceAllocation
 
-- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
-- β”‚ MISSION_ID β”‚ SHIP_REGISTRYβ”‚ CREW_SIZE β”‚ DURATION_DAYS β”‚ PRIORITY β”‚ ENERGY_UNITS β”‚ FOOD_SUPPLY_KG β”‚ MED_KITS β”‚ PRIORITY_LEVEL β”‚
-- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-- β”‚ M001       β”‚ NCC-1701     β”‚ 150       β”‚ 90            β”‚ 9        β”‚ 13500        β”‚ 40500          β”‚ 30       β”‚ High           β”‚
-- β”‚ M002       β”‚ NX-74205     β”‚ 100       β”‚ 90            β”‚ 4        β”‚ 4000         β”‚ 27000          β”‚ 20       β”‚ Medium         β”‚
-- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 

β”€β”€β”€βœ±*.q:q✱*.:q✧*.q✰*.:q✧*.q:q*.q✱ ───