---
title: "How to use Procedure in SQL?"  
description: "How to use Procedure in SQL?"  
author: "Abhishek Srivasatava"  
published: 2016-09-30  
updated: 2020-09-22  
canonical: https://www.mindstick.com/interview/23080/how-to-use-procedure-in-sql  
category: "mysql"  
tags: ["sql server", "sql", "sql server 2008"]  
reading_time: 2 minutes  

---

# How to use Procedure in SQL?

## Simple way to learn about the Procedure:

Procedure is a group of SQL statement.

Syntax for the procedure

```
CREAT PROCEDURE PROC1(          NUM1           INT)ASBEGIN          IF( NUM1>100)             BEGIN                      PRINT ‘PASS’             END          ELSE               BEGIN                        PRINT ‘FAIL’             ENDEND 
```

\

**How to use this concept in programming?**

As it is widely used in most of the application. So one should aware about this concept practically.

Suppose we have insert command from the user side then first we need to verify is that upcoming data is already exist or not.

**Here is the small program for the above example:**

```
CREATE PROCEDURE Proc_Info(@PRSN_INTN_ID INT,@EMPL CHAR (20),@NAME CHAR (20),@REFERENCE INT) ASBEGIN          IF NOT EXISTS (SELECT PRSN_INTN_ID FROM EE_EMPL_CAT1 WHERE
                                PRSN_INTN_ID = @PRSN_INTN_ID)                     BEGIN                               INSERT INTO EE_EMPL_CAT1 (PRSN_INTN_ID,[EMPL_STAT_CD],[NAME],REFERENCE_id)                                VALUES (@PRSN_INTN_ID,@EMPL,@NAME,@REFERENCE)                     END         ELSE                     BEGIN                               PRINT 'DATA ALREADY EXISTS'                     ENDEND 
```

## Answers

### Answer by Abhishek Srivasatava

## Simple way to learn about the Procedure:

Procedure is a group of SQL statement.

Syntax for the procedure

```
CREAT PROCEDURE PROC1(          NUM1           INT)ASBEGIN          IF( NUM1>100)             BEGIN                      PRINT ‘PASS’             END          ELSE               BEGIN                        PRINT ‘FAIL’             ENDEND 
```

\

**How to use this concept in programming?**

As it is widely used in most of the application. So one should aware about this concept practically.

Suppose we have insert command from the user side then first we need to verify is that upcoming data is already exist or not.

**Here is the small program for the above example:**

```
CREATE PROCEDURE Proc_Info(@PRSN_INTN_ID INT,@EMPL CHAR (20),@NAME CHAR (20),@REFERENCE INT) ASBEGIN          IF NOT EXISTS (SELECT PRSN_INTN_ID FROM EE_EMPL_CAT1 WHERE
                                PRSN_INTN_ID = @PRSN_INTN_ID)                     BEGIN                               INSERT INTO EE_EMPL_CAT1 (PRSN_INTN_ID,[EMPL_STAT_CD],[NAME],REFERENCE_id)                                VALUES (@PRSN_INTN_ID,@EMPL,@NAME,@REFERENCE)                     END         ELSE                     BEGIN                               PRINT 'DATA ALREADY EXISTS'                     ENDEND 
```


---

Original Source: https://www.mindstick.com/interview/23080/how-to-use-procedure-in-sql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
