1

I was referring to Java Constant Field Values and thought if boundary values ( say MIN_VALUE, MAX_VALUE in case of Numeric data types ) can be retrieved for data types using an SQL query.

For example

select  
    int.signed_min_value as int_sgnd_min,  
    int.unsigned_min_value as int_usgnd_min,  
    int.signed_max_value as int_sgnd_max,  
    int.unsigned_max_value as int_usgnd_max,  
    int.storage_bytes as int_bytes  
from dual;  

Should be resulting

+--------------+---------------+--------------+---------------+-----------+
| int_sgnd_min | int_usgnd_min | int_sgnd_max | int_usgnd_max | int_bytes |
+--------------+---------------+--------------+---------------+-----------+
|  -2147483648 |             0 |   2147483647 |    4294967295 |       4   |
+--------------+---------------+--------------+---------------+-----------+

Above results are storage and range values defined for MySQL integer data type.
Other data type storage requirements in MySQL are as defined here.

I gave a sample on numeric data type only but I am also expecting a possibility for other data types.

I do am aware that we can only select columns and expressions, but trying to understand if there is such a facility in SQL like in Java and other programming languages.

1
  • @Diego Well, no constraint. Generic is appreciated. Commented Jul 5, 2012 at 14:12

1 Answer 1

1

if you mean Sql Server, you can get that info from the sys.types table. If you do:

select * from sys.types
where name='int'

you can check the max_length, which indicates the Maximum length (in bytes) of the type. So int = 4 bites whihc gives you -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647)

Sign up to request clarification or add additional context in comments.

1 Comment

In SQL Server, how do I get range values if name='date'? AFAIK, Oracle date ranges from January 1, 4712 BC to December 31, 9999 AD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.