MAXVALUE
MAXVALUE in SQL is part of the sequence generator functionality. It sets the upper limit of possible numbers that a sequence can generate. A sequence stops producing new numbers when this limit has been reached, unless the sequence cycles.
Example
Output
MySQL doesn’t provide direct output for MAXVALUE
used in the above way. The MAXVALUE
99999 here just limits the id
field to not exceed it.
Explanation
The MAXVALUE
keyword in SQL specifies the maximum value a sequence of numbers can have. When we specify MAXVALUE
for AUTO_INCREMENT
in a MySQL CREATE TABLE
statement, MySQL will stop generating new numbers for the id
column once it reaches the specified MAXVALUE
.
Example
Output
Explanation
In the given SQL code, we created a table example_table
with id
and value
as columns. The id
column is a serial type, meaning a unique number gets generated for each new record. We then inserted 5 rows in this table with different values for the value
column. Finally, we used the MAX()
function to retrieve the maximum value from the value
column. The function returned 30 which is the maximum value among all values in the value
column.
Example
Output
Explanation
MAX(salary)
is an aggregate function that finds the maximum salary
among all employees in the employees
table. The column is aliased as max_salary
for a clearer output display.