Skip to main content

How to Create a Stored Procedure in MySQL


In this article, we will describe how to create a stored procedure in MySQL for your acknowledgment,which may come superbly handy with your advance preparation of MySQL interview questions. MySQL excellently supports stored procedures which are able to execute a set of codes by enforcing relevant business logic.
So, What’s a Stored Procedure?
It can be defined as a sub program present in a regular computing language, stored in a database. It has a name, SQL statements, SQL command logic,and a parameter list. It allows developers to create SQL queries which can be stored and executed on the server. These can also be cached and reused. The prime purpose of MySQL stored procedures is to hide direct SQL queries from the code, thus improving the performance of database operations such as update, delete,and select data.
Let’s Create a Simple MySQL Stored Procedure
Before we start creating a MySQL stored procedure;we would like to repeat that practicing these steps could be extremely helpful with the preparation of many important MySQL interview questions. Here, we will develop a simple stored procedure named - Get All Products()to help you better understand the syntax. This procedure will select all the available products from the product table.
·         At first, launch MySQL client tool and use below-mentioned command.
 DELIMITER //
 CREATE PROCEDURE Get All Products()
   BEGIN
   SELECT *  FROM products;
   END //
 DELIMITER ;


Now, let’s briefly describe the stored procedure mentioned above.
·         The DELIMITER// statement used above is not a part of the stored procedure syntax,andit changes the standard semicolon(;)delimiter to another. Here semicolon is transformed to double slashes. It is required to pass the whole stored procedure to the server rather than each statement at a time due to MySQL tool interpretation.
·         The END keyword here followed by the delimiter // indicates the end of the stored procedure.
·         The last used command DELIMITER ;changes the delimiter again to the semicolon (;).
·         The statement CREATE PROCEDURE will create the new stored procedure, which will be followed by the name of the stored produce. In this case, we have used Get All Products as our stored procedure name, after which we have put the parentheses to continue.
·         The section present in between the BEGIN and END is the body of our stored procedure. We will have to the declarative SQL statements in this body section to handle the business logic. Here, we have used a SELECT statement to query the data from our product table.
As it’s a tedious process to write complex stored procedures in MySQL client tool, almost every GUI tool available for MySQL allows users to create new stored procedures with an intuitive interface.
To get more MySQL interview questions with their best-suggested answers, please browse our website Best Interview Question today, an exclusive portal to support beginners as well as experienced personnel.





Comments

Popular posts from this blog

What is the use of $ symbol in JQuery

At present, a number of potential candidates are inclined toward the segment of JQuery.  This is another reason for which you may prefer JQuery interview questions . The symbol $ has a lot to do with the JavaScript as in language. Once you start working over the JQuery, then you will eventually learn about the usage of $ sign. Symbol $ deals with defining the JQuery in particular. With the surveillance of $, the JQuery variable distinguishes them from the objects standardized JavaScript.In this article, we will learn the use of a $ symbol in JQuery. The symbol $ is utilized by JavaScript for the variable name. In brief, you can say that JQuery is a JavaScript library that focuses on less writing and more doing. It is not much involved in programming but has the tools that simplify the writing of standard Javascript. Later it is the association of symbol “$.” Also, there are many crucial  JQuery interview questions which will help you during the interview. JQuery syntax JQ

Why Is WordPress So Popular?

Introduction WordPress is an online, open-source website development and creation tool which is written in PHP language.  In other words, WordPress is the most powerful blogging and website Content Management System (CMS). WordPress features include a plug-in architecture and template system. Nowadays, WordPress is used by more than 19% of the top million websites.  It is of many PHP/ MySQL content management systems that allow content editors to use a web interface to maintain their websites instead of editing and uploading HTML files to a server.  The latest stable release of WordPress is Version 3.9.1. In this blog, a comprehensive summary of the WordPress popularity is provided to the users. Moreover, users can also create WordPress Interview Questions website on the web with the use of the WordPress platform. WordPress is so popular in today’s scenario due to the following features Simplicity and Flexibility With the help of WordPress, users can create any variety o