Collections:
DEFAULT() - Table Column Default Value
How to obtain the default value of a table column using the DEFAULT() function?
✍: FYIcenter.com
DEFAULT(col) is a MySQL built-in function that returns the default value of a given table column. For example:
CREATE TABLE MyTable (Weight FLOAT, Height FLOAT DEFAULT 1.7); INSERT INTO MyTable (Weight) VALUES (70); INSERT INTO MyTable (Weight, Height) VALUES (72, DEFAULT(Height)+0.1); SELECT Weight, Height, DEFAULT(Height) FROM MyTable; -- +--------+--------+-----------------+ -- | Weight | Height | DEFAULT(Height) | -- +--------+--------+-----------------+ -- | 70 | 1.7 | 1.7 | -- | 72 | 1.8 | 1.7 | -- +--------+--------+-----------------+
Note that calling DEFAULT() on a column that has no default value may get NULL or error. For example,
SELECT Weight, Height, DEFAULT(Weight) FROM MyTable; -- +--------+--------+-----------------+ -- | Weight | Height | DEFAULT(Weight) | -- +--------+--------+-----------------+ -- | 70 | 1.7 | NULL | -- | 72 | 1.8 | NULL | -- +--------+--------+-----------------+ SELECT DEFAULT(name) FROM mysql.help_topic; ERROR 1364 (HY000): Field 'name' doesn't have a default value
Reference information of the DEFAULT() function:
DEFAULT(col): val Returns the default value of a given table column. Arguments, return value and availability: col: Required. The table column to be examined. val: Return value. The default value of the column. Available since MySQL 4.0.
⇒ EXTRACTVALUE() - Extracting Text Content from XML
⇐ CONVERT() - Character Set Conversion
2023-12-19, 220🔥, 0💬
Popular Posts:
How To Calculate Age in Days, Hours and Minutes in SQL Server Transact-SQL? On many Web sites, news ...
How To Generate CREATE TABLE Script on an Existing Table in SQL Server? If you want to know how an e...
What Are Out-of-Range Errors with DATETIME values in SQL Server Transact-SQL? When you enter DATETIM...
What Are Bitwise Operations in SQL Server Transact-SQL? Bitwise operations are binary operations per...
How To Change the Name of a Database User in SQL Server? If you want to change the name of an existi...