sql / beginner
Snippet
Precision Decimal Storage for Currency Data
The DECIMAL numeric data type stores exact decimal numbers with specified precision and scale. It is preferred for monetary calculations to prevent rounding errors associated with floating-point types.
snippet.sql
sql
1
2
3
4
CREATE TABLE product_prices (product_id INT,unit_price DECIMAL(10, 2));
Breakdown
1
CREATE TABLE product_prices (
Begins creation of a table named product_prices.
2
product_id INT,
Defines product_id as a standard integer column.
3
unit_price DECIMAL(10, 2)
Specifies a numeric column with 10 total digits and 2 decimal places to prevent floating-point inaccuracies.
4
);
Closes the table definition statement.