Simulating Mercury’s Orbital Motion Using Pure T-SQL (NASA 2025 Dataset)

  • SQL Server is typically viewed as a transactional or analytical database engine. However, it is also a deterministic numerical computation environment capable of handling large-scale scientific data.

    This article demonstrates how Microsoft SQL Server can:

    Store astronomical datasets

    Compute derived physical quantities

    Reconstruct velocity from an algebraic invariant

    Compare simulation results against real observational data

    Perform statistical validation entirely in T-SQL

    The dataset used in this example consists of publicly available orbital data for Mercury (2024–2025).

    1. Designing the Data Model

    We begin by storing the 2024 reference dataset.

    CREATE TABLE Mercury_2024 (

    ObsDate DATE PRIMARY KEY,

    Position_m FLOAT,

    Velocity_ms FLOAT,

    Mass_kg FLOAT

    );

    INSERT INTO Mercury_2024 VALUES

    ('2024-01-01', 5.16E+10, 5.33E+04, 3.30E+23),

    ('2024-04-01', 6.97E+10, 3.90E+04, 3.30E+23),

    ('2024-07-01', 5.36E+10, 5.20E+04, 3.30E+23),

    ('2024-10-01', 6.95E+10, 3.92E+04, 3.30E+23),

    ('2024-12-31', 4.64E+10, 5.81E+04, 3.30E+23);

    This table stores:

    Position (meters)

    Velocity (m/s)

    Mass (kg)

    2. Computing Derived Quantities

    We compute two derived values:

    Momentum: p = m × v

    Invariant quantity: C = x × p

    SELECT

    ObsDate,

    Position_m,

    Velocity_ms,

    Mass_kg,

    Mass_kg * Velocity_ms AS Momentum,

    Position_m * (Mass_kg * Velocity_ms) AS InvariantValue

    FROM Mercury_2024;

    This establishes a large-scale constant on the order of 10^38.

    3. Reconstructing Velocity Algebraically

    If we define a target invariant value:

    DECLARE @Invariant FLOAT = 8.90E+38;

    Velocity can be reconstructed using:

    v=Invariantx·mv = \frac{Invariant}{x \cdot m}v=x·mInvariant?Implementation:

    SELECT

    ObsDate,

    @Invariant / (Position_m * Mass_kg) AS SimulatedVelocity

    FROM Mercury_2024;

    This demonstrates that SQL Server can directly perform high-magnitude scientific calculations.

    4. Loading Observed 2025 Data

    CREATE TABLE Mercury_2025_NASA (

    ObsDate DATE PRIMARY KEY,

    Position_m FLOAT,

    Velocity_ms FLOAT,

    Mass_kg FLOAT

    );

    INSERT INTO Mercury_2025_NASA VALUES

    ('2025-01-01', 5.16E+10, 53400, 3.30E+23),

    ('2025-04-01', 6.97E+10, 38900, 3.30E+23),

    ('2025-07-01', 5.49E+10, 50400, 3.30E+23),

    ('2025-10-01', 6.83E+10, 39800, 3.30E+23),

    ('2025-12-31', 4.61E+10, 58900, 3.30E+23);

    5. Validation Against Observed Data

    We now compute relative error directly in SQL:

    DECLARE @Invariant FLOAT = 8.90E+38;

    SELECT

    N.ObsDate,

    N.Velocity_ms AS NASA_Velocity,

    @Invariant / (N.Position_m * N.Mass_kg) AS Simulated_Velocity,

    (

    (@Invariant / (N.Position_m * N.Mass_kg) - N.Velocity_ms)

    / N.Velocity_ms

    ) * 100 AS Relative_Error_Percent

    FROM Mercury_2025_NASA N

    ORDER BY N.ObsDate;

    Average deviation:

    SELECT

    AVG(

    ABS(

    (@Invariant / (Position_m * Mass_kg) - Velocity_ms)

    / Velocity_ms

    ) * 100

    ) AS AvgRelativeErrorPercent

    FROM Mercury_2025_NASA;

    Observed average relative deviation: approximately 1–2%.

    6. Precision Considerations: FLOAT vs DECIMAL

    Because values approach 10^38:

    FLOAT provides performance and simplicity

    DECIMAL(38,10) increases determinism

    Large-scale scientific workloads may benefit from DECIMAL

    Example alteration:

    ALTER TABLE Mercury_2025_NASA

    ALTER COLUMN Position_m DECIMAL(38,10);

    7. Encapsulating Logic in a Stored Procedure

    CREATE OR ALTER PROCEDURE SimulateMercury

    @Invariant FLOAT

    AS

    BEGIN

    SET NOCOUNT ON;

    SELECT

    ObsDate,

    Velocity_ms AS NASA_Velocity,

    @Invariant / (Position_m * Mass_kg) AS Simulated_Velocity,

    (

    (@Invariant / (Position_m * Mass_kg) - Velocity_ms)

    / Velocity_ms

    ) * 100 AS Relative_Error_Percent

    FROM Mercury_2025_NASA

    ORDER BY ObsDate;

    END;

    Execution:

    EXEC SimulateMercury @Invariant = 8.90E+38;

    8. Performance and Execution Plan

    Key characteristics:

    Clustered index seek on primary key

    Scalar arithmetic operations

    Linear complexity O(n)

    No external computation engine required

    SQL Server handles large-magnitude arithmetic efficiently within standard query execution.

    9. Why This Matters

    This exercise demonstrates that SQL Server can serve as:

    A deterministic scientific calculation environment

    A validation engine for observational datasets

    A reproducible numerical workflow system

    A self-contained simulation platform

    All computations, validation, and statistics are performed directly inside T-SQL without external scripting languages.

    Conclusion

    Relational databases are often underestimated as scientific tools. This example shows that SQL Server can:

    Store astronomical-scale data

    Perform algebraic reconstruction

    Validate real observational measurements

    Maintain reproducibility within a structured query environment

    While SQL Server is not a physics engine, it is fully capable of supporting structured scientific computation pipelines when problems are algebraically defined.

Viewing post 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply