Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 516.6k

Column Max Value

Sep 2 2024 1:51 AM

Hi

  I have below stored procedure to get last  max value. How to ensure that at same time 2 Users does not get same value , though it is Primary Key.

CREATE PROCEDURE GetMaxValue(IN tableName VARCHAR(255), IN columnName VARCHAR(255))
BEGIN
    SET @query = CONCAT('SELECT MAX(', columnName, ') AS max_value FROM ', tableName);
    PREPARE stmt FROM @query;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
END
SQL
 

Thanks


Answers (4)