MySQL Forums
Forum List  »  Stored Procedures

Re: Does Table Exist
Posted by: Jon Stephens
Date: April 30, 2020 11:16AM

DELIMITER //

CREATE PROCEDURE TableExists (IN name VARCHAR(64), OUT found INT)
  BEGIN
    SELECT (COUNT(*) > 0) INTO found 
    FROM INFORMATION_SCHEMA.TABLES 
    WHERE TABLE_NAME = name;
  END //

DELIMITER ;

CALL TableExists('t1', @foundit);

SELECT @foundit; # 1 if table exists, 0 if not

Jon Stephens
MySQL Documentation Team @ Oracle

MySQL Dev Zone
MySQL Server Documentation
Oracle

Options: ReplyQuote


Subject
Views
Written By
Posted
766
April 29, 2020 02:15PM
412
April 29, 2020 03:25PM
374
May 04, 2020 02:19AM
Re: Does Table Exist
412
April 30, 2020 11:16AM
391
May 04, 2020 02:21AM
487
June 11, 2020 11:25AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.