How to Represent Equation with Variables in Relational Database I am building an application to store the different formulas used for different subjects in school, and I have drawn the following database diagram to depict that scenario:



I am having trouble figuring out how to represent an equation in a relational database. 

Each equation is made up of variables of different types. For example,

E=mc^2


Has the following components:


E, which is energy in joules(J), which is actually kg*m^2*s^2.
m, which is mass in kilograms(kg), which cannot be broken down further
c, which is the speed of light, with the value of 3*10^8, and units of m/s


The problem is not the representation of the string of the equation within the database. Rather, I want to represent the relationship between the individual variables within an equation.

How should I go about representing these different types of variables within the same database?
Here's one suggestion. Since you used the term component, I'll stick with that, but maybe theres a better term?

CREATE TABLE COMPONENTS
( COMPONENT_ID INT NOT NULL PRIMARY KEY
, ABBREVIATION CHAR(1) NOT NULL -- Example 'E'
, DESCRIPTION VARCHAR(50) NOT NULL -- Example 'Energy'
);

CREATE TABLE EQUATION_COMPONENT
( EQUATION_ID ...
, COMPONENT_ID ...
,    PRIMARY KEY ( EQUATION_ID, COMPONENT_ID )
,    FOREIGN KEY ( EQUATION_ID ) REFERENCES EQUATIONS ( EQUATION_ID )
,    FOREIGN KEY ( COMPONENT_ID ) REFERENCESCOMPONENTS ( COMPONENT_ID )
);


If you, for example, want to find all equations concerning both Mass and Energy:

SELECT EQUATION_ID
FROM EQUATION_COMPONENT
WHERE COMPONENT_ID IN ( id:s for Mass and Energy )
GROUP BY EQUATION_ID
HAVING COUNT(COMPONENT_ID) = 2