In this article, we will learn how to get the return value using the SQL stored procedure Output parameter. There are some scenarios where we need the return value using the SQL stored procedure such as whenever a new order is created into the database, then return an OrderId to the user for reference.
Let's consider the similar scenario and we have the following table OrderDetails which maintains the processed orders as shown in the following image.
I hope you have created the same table structure as shown above. Now create the stored procedures to get the return value as in the following code snippet.
CreatePROCEDURE PlaceOrder
(
@Product varchar(50),
@Amount decimal(18,2),
@OrderId int out
)
ASBEGINSET NOCOUNT ON;
INSERTINTO [dbo].[OrderDetails]
(
Product,
Amount
)
VALUES
(
@Product,
@Amount
)
select @OrderId=isnull(max(OrderId),0) from OrderDetails
END
Now execute the stored procedure using the SQL editor as follows.
In the preceding, The stored procedure inserts the new order into the SQL table and return the out value as OrderId using the stored procedure.
Summary
I hope from the preceding explanation, you have learned how to return the value using the SQL stored procedure. If you have any queries, then you can send using the following comment box.
In this article, we will learn how to use the SQL stored procedures with dapper ORM by writing a few lines of code. Let's consider we have the following values that need to be inserted into the SQL database using a stored procedure with the help of dapper ORM.
Name
City
Address
Create the stored procedure to map the above parameters.
In this article, we will learn how to get the return value using the SQL stored procedure Out parameter. There are some scenarios where we need the return value using the SQL stored procedure such as whenever a new order is created into the database, then return an OrderId to the user for reference.
Let's consider the similar scenario and we have the following table OrderDetails which maintains the processed orders as shown in the following image.
I hope you have created the same table structure as shown above. Now create the stored procedures to get the return value as in the following code snippet.
CreatePROCEDURE PlaceOrder
(
@Product varchar(50),
@Amount decimal(18,2),
@OrderId int out
)
ASBEGINSET NOCOUNT ON;
INSERTINTO [dbo].[OrderDetails]
(
Product,
Amount
)
VALUES
(
@Product,
@Amount
)
select @OrderId=isnull(max(OrderId),0) from OrderDetails
END
Now execute the stored procedure using the SQL editor as follows.
In the preceding, The stored procedure inserts the new order into the SQL table and return the out value as OrderId using the stored procedure.
Summary
I hope from the preceding explanation, you have learned how to return the value using the SQL stored procedure. If you have any queries, then you can send using the following comment box.
In this article we will learn how to delete the records from the Azure SQL table using step by step, so beginners and students can also understand.
Prerequisites
If you are new to the Azure SQL, then please watch my following videos on the Azure SQL database.
How To Create Azure SQL Database
How To Connect Azure SQL Database
Let us consider we have the Employee table in our Azure SQL Server database having the following records,
The following two commands are used to delete the records from the Azure SQL table.
Delete
Truncate
Using Delete Command
The delete command is used to delete all the records from the table or specific records by using the Where clause.
What does Delete Command Do?
The Delete command can be used with or without a WHERE clause.
The Delete command removes all records if you use it without the where condition.
The Delete command removes the one or more rows based on the condition given in the Where clause.
The Delete command maintains the logs of each deleted record. This helps to keep track of each deleted record.
The Delete command activates triggers. It means you can take certain action whenever you delete the record, such as inserting the deleted records in some other table etc.
The Delete can be rolled back. It means that if the records are deleted by mistake, then we can restore the deleted record back to the table.
The Delete command does not reset the identity of the table. It means that when you delete all the records from the table having Id between 1 and 10, then after adding the new record in the table, it will start with the ID count from 11, not 1.
Deleting Specific Records
To delete the specific record from the table, we need to use the where clause.
Syntax
deletefrom TableName where ColumName=value
Example
deletefrom Employee where Id=1
The above query will delete the records from the Employee table which has id 1. After deleting the record, then the table records will look like as follows.
Deleting all records
To delete all records from the table, we need to write a query without the where clause.
Example
deletefrom Employee
The above query will delete all records from the Employee table.
Using Truncate command
The truncate command removes all the rows from a table.
What does Truncate Command Do?
Truncate removes all rows from a table, but the table structure such as columns, constraints, indexes remains.
Truncate command can not be used with where or any condition.
Truncate command can not be activates the trigger, It means we can not take any action on deleted records.
Truncate cannot be rolled back, it means deleted records from the table cannot be restored.
Truncate resets the identity of the table, it means that when you delete all the records from the table having Id between 1 and 10, then after adding the new record in the table, it will start with the ID count from 1, not 11.
Truncate command can not be maintains the logs of deleted record. It means we can not keep the track of each deleted record.
Example
truncatetable Employee
The preceding query deletes all the records from the table.
Summary
I hope this article helped to know how to delete records from the Azure SQL database. If you have a suggestion related to the article, then please comment using the comment box.
In this article we will learn about the Azure SQL alter statement. In the previous article we have learned how create and connect to the Azure SQL database. If you are new to the Azure SQL, then please watch my following videos on the Azure SQL database.
How To Create Azure SQL DataBase
How To Connect Azure SQL DataBase Using SQL Management Studio
What is SQL Alter Table Statement?
Alter statement used to modify the structure of the existing table. The alter statement used is to add, drop the table column. It can also be used to change the data types of the column etc. Let us consider we have the table having name Employee in our Azure SQL Server database having the following records,
Add Column To Existing Table Using Alter Statement
The following SQL query will add the new column Salary into the existing table.
ALTERTABLE Employee
ADD salary decimal(50);
You can alter the multiple columns at a time, the following query will alter the multiple columns of the existing table.
In previous video tutorial Creating Azure SQL DataBase (Cloud ) Step by Step We have leaned how to create Azure SQL DataBase , Now this video tutorial guides you how to connect our created Azure SQL DataBase (cloud) using SQL Server management studio . This video tutorial covers the following topics
What is SQL Server Management studio?
Configuring firewall.
Restrict & Allow Client Machines to Access DataBase.
Map Client IP Address .
Why we need to MAP Client IP Address.
Now Let's watch
Summary
I hope this video tutorial is useful for all viewers , If you like this video then , don't forget to subscribe compilemode.comYouTube Channel.
Many times in interviews, one question is commonly asked, "What is the difference between stored procedure and function?". So, considering the above requirement, I have decided to write this blog to help beginners and job seekers who might want to know about it.
What is a SQL Stored Procedure?
A Stored Procedure is a group of logical SQL statements to perform a specific task, such as insert, select, update, and delete operations on a table, and so on, which are stored in a SQL database.
What is a SQL function ?
A Function is a logical group of SQL statements that perform an operation on the group of SQL statements and return a single value. It is also stored in a database.
Summary
I hope this blog is useful for all readers and that these differences are enough to impress the interviewer. If you have any suggestions, then please contact me.