sql / beginner
Snippet
Storing Exact Monetary Values using the DECIMAL Data Type
The DECIMAL data type stores exact numeric values, making it ideal for financial data where rounding errors are unacceptable. DECIMAL(10, 2) allows up to 10 total digits, with 2 digits after the decimal point.
snippet.sql
sql
1
2
3
4
CREATE TABLE account_balances (account_id INT,balance DECIMAL(10, 2));
Breakdown
1
CREATE TABLE account_balances (
Starts the creation of a new database table named account_balances.
2
account_id INT,
Defines account_id as an integer column for identification numbers.
3
balance DECIMAL(10, 2)
Defines balance as a fixed-point decimal column with 10 total digits and 2 decimal places.
4
);
Closes the table definition statement.