skip to Main Content

I want to create a SQL stored procedure that checks passwords at login. This should be a very common question however I could not find an answer anywhere to my specific question, which is about data types, or perhaps something like that. I am using a MySQL database but I am unsure what type of SQL I am using specifically. Here’s my SQL:

CREATE PROCEDURE SelectAllUsers @Password varchar(12)
AS
SELECT * FROM Logins WHERE Password = @Password
GO;

This image shows where I get an error for some reason, which is beyond me

2

Answers


  1. You don’t specify the SQL dialecct that you are using, and the syntax can be different between them.
    The following should work for Postgres:

    CREATE PROCEDURE SelectAllUsers (IN in_password varchar(12))
    BEGIN
        SELECT * FROM Logins WHERE Password = in_password;
    END;
    

    You can find more information about the syntax in the docs: https://www.postgresql.org/docs/current/sql-createprocedure.html

    Login or Signup to reply.
  2. If you are using MySQL, navigate to Stored Procedure under you DB Schema, right click and then click ‘Create Stored Procedure’. Copy below query. Change definer (root@localhost) accordingly.

    CREATE DEFINER=`root`@`localhost` PROCEDURE `SelectAllUsers`(IN in_password VARCHAR(12))
    BEGIN
    SELECT * FROM Logins WHERE Password = in_password;
    END
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search