SQL Server SMALLMONEY Data Type
SMALLMONEY
is a data type in SQL Server used for storing currency values. It is used to store currency amounts less than 10^4
, with a precision of 4 decimal places, and occupies 4 bytes of space. In computer science, SMALLMONEY
is considered a fixed-point data type that can be used in applications that require currency calculations.
Syntax
The syntax for creating a column of SMALLMONEY
type is as follows:
column_name SMALLMONEY
Usage
The SMALLMONEY
data type is primarily used for storing small currency amounts. Compared to the MONEY
data type, it has lower precision but occupies less space. Therefore, when storage space needs to be saved, SMALLMONEY
data type can be used as a priority. In some financial applications, small currency amounts are frequently used, such as calculating discounts, taxes, etc., and SMALLMONEY
data type can be used in such scenarios.
Examples
Here are two examples of using the SMALLMONEY
data type.
-
Creating a
sales
table with aprice
column for storing the sales unit price.CREATE TABLE sales ( id INT PRIMARY KEY, product_name VARCHAR(50), price SMALLMONEY );
-
Inserting data into the
sales
table and querying the values in theprice
column.INSERT INTO sales (id, product_name, price) VALUES (1, 'Product A', 9.99), (2, 'Product B', 19.99); SELECT price FROM sales;
The result is as follows:
price 9.9900 19.9900
Conclusion
SMALLMONEY
data type is used for storing small currency amounts. It has lower precision but occupies less space, and is suitable for scenarios that require small currency calculations. In practical applications, SMALLMONEY
or other currency data types can be selected based on the requirements.