Stored Procedure in SQL Server With Examples

What Is a Stored Procedure In SQL Server?

 Stored Procedure : A stored procedure in SQL Server is a precompiled collection of SQL statements that get cached and stored in the database in order to reused over and over again whenever required.

Advantage of using Stored Procedure

    • A stored procedure (SP) provides the reusability of SQL code as we can simply call the stored procedure Instead of writing the same SQL statements over and over again.
    • It allows reducing the network traffic by executing the SQL statements at the server-side rather than sending hundreds lines of SQL queries over the network.
    • A stored procedure can be used as a security mechanism by granting a user to execute only the stored procedure instead of allowing permission on the table.
    • It allows faster execution of SQL statements in order to enhance the performance.

Continue reading “Stored Procedure in SQL Server With Examples”

CREATE, ALTER, AND DROP DATABASE IN SQL SERVER

In this article, we will discuss how to Create, Alter, and Drop a database in SQL Server.
In my previous article, we have discussed all about the Types of SQL Commands.

Database Introduction

 Database  : In the SQL server a database is a place to store the data in an electronic format. It is an organized collection of database objects such as tables, views, functions, stored procedures, triggers and so on.
It allows a user to easily access or manipulate the data.

SQL server database

Create Database In SQL Server

In SQL Server, there are two ways to create a user-defined database, either by using the Transact-SQL statements or by using SQL Server Management Studio.

Continue reading “CREATE, ALTER, AND DROP DATABASE IN SQL SERVER”

What is SQL Server – Types of SQL Commands

SQL Commands

What is SQL?

 SQL  stands for Structured Query Language. SQL is a language used to store, retrieve, and manipulate data in a Relational Database Management Systems (RDMS)
such as SQL Server, Oracle, MySQL, etc.
SQL allows a user to communicate with the database using commands.

Features of SQL

    • SQL is used to create, truncate, and drop the database and table using SQL commands.
    • SQL can be used to execute the queries against the database to perform various operations.
    • SQL is used to create a function, stored procedure, trigger and view in a database.
    • It provides security and allows a users to set permissions on the tables, stored procedures, and views in the database.

What is a Database?

A database is a place to store the data in an electronic format. It is an organized collection of database objects such as tables, views, functions, stored procedures, triggers, and so on.
It allows a user to easily access or manipulate the data.

Continue reading “What is SQL Server – Types of SQL Commands”

C# Monitor class in multithreading with examples

What Is Monitor Class In C#?

Monitor class: In C#, the Monitor class provides a wait based synchronization mechanism that allows only one thread to access a critical section of code at a time to avoid the race condition.
Here all the other threads have to wait and halt the execution until the locked object is released.

The  Monitor.Enter  method is used to acquire an exclusive lock on the object whereas  Monitor.Exit  method is used to release the locked object.

In order to use the Monitor class in a multithreading , we first need to import the  System.Threading  namespace.

C# Monitor class in multithreading

Continue reading “C# Monitor class in multithreading with examples”

Lock Statement In C# – When To Use Lock keyword

This post series we will go through the understanding of the lock statement, monitor, mutex, and semaphore available in C#.

All of these classes provide a synchronization mechanism to protect the shared code or resources in a multithreaded application.

Let’s first understand the lock statement in C#.

C# Lock Statement

Lock Statement: In C#, the  lock  is a synchronization mechanism that allows only one thread to access a specified piece of code or a common field at a time.

It is mainly used to achieve an exclusive lock to avoid inconsistent output while reading and writing to a common variable in a multithreaded environment.

Generally, the  lock  keyword is placed around a critical section of code, where we want to allow only one thread to access the resource at a time.
All the other threads have to wait and halt the execution until the locked object is released.

Pictorial representation of mutual exclusion of lock

Lock in C#

Continue reading “Lock Statement In C# – When To Use Lock keyword”

Page 1 of 2
1 2