Sql cursor | Understanding about CURSOR in SQL | how to create and use of cursor | Cursor in sql

Опубликовано: 02 Октябрь 2024
на канале: rejawebs
489
6

Hello Every one
Welcome to tutorial on database cursor in SQL
In this tutorial we will try to know about what is cursor and how to use cursor in sql.

Database Cursor:
A database cursor is an object that enables traversal over the rows of a result set.
A cursor can hold more than one row, but can process only one row at a time.

SQL Syntax:
DECLARE Cursor_Name CURSOR
READ_ONLY FAST_FORWARD FOR
SELECT Column1,Column1,.....,ColumnN FROM Table_Name
OPEN Cursor_Name
FETCH NEXT FROM Cursor_Name INTO @Variable1,@Variable2........,@VariableN
WHILE (@@FETCH_STATUS = 0)
BEGIN
--Your Logics
FETCH NEXT FROM Cursor_Name INTO @Variable1,@Variable2........,@VariableN
END
CLOSE Cursor_Name
DEALLOCATE Cursor_Name
Now, take a look to have example in sql server...

DECLARE
@Fistname NVARCHAR(200),
@Lastname NVARCHAR(200),
@Email NVARCHAR(200),
@GrossSalary DECIMAL(18,2);
DROP TABLE IF EXISTS #TempEmployeeInfo
CREATE TABLE #TempEmployeeInfo
(
Fistname NVARCHAR(50),
Lastname NVARCHAR(50),
Email NVARCHAR(50),
GrossSalary DECIMAL(18,2),
);
DECLARE Cursor_Employee CURSOR
READ_ONLY FAST_FORWARD FOR
SELECT
Fistname
,Lastname
,Email
,GrossSalary
FROM [dbo].[EmployeeInfo]
OPEN Cursor_Employee
FETCH NEXT FROM Cursor_Employee INTO @Fistname,@Lastname,@Email,@GrossSalary
WHILE (@@FETCH_STATUS = 0)
BEGIN
--Your Logics
INSERT INTO #TempEmployeeInfo
SELECT
@Fistname Fistname
, @Lastname Lastname
, @Email Email
, @GrossSalary GrossSalary
FETCH NEXT FROM Cursor_Employee INTO @Fistname,@Lastname,@Email,@GrossSalary
END
CLOSE Cursor_Employee
DEALLOCATE Cursor_Employee
SELECT *FROM #TempEmployeeInfo
CLOSE Cursor_Employee
DEALLOCATE Cursor_Employee


Searchable Keywords:
Cursors in sql server
SQL Cursors - how and when to use them
PL/SQL Database Cursors In Oracle Database
CURSORS IN PL/SQL WITH EXAMPLES | PL/SQL TUTORIAL
SQL Server Programming Part 12 - Cursors
SQL Cursors Hindi | Cursors in Sql server | Cursor in database | T-SQL Cursor
Cursor in SQL Server 2019 with examples
Stored Procedure in SQL in Hindi | SQL Tutorial
SQL Server Cursor Example Tamil
Cursor in SQL - Hindi
What is a Cursor? Why to avoid them?
SQL Server Cursor vs While Exists
Cursor in SQL Introduction | SQL Tutorial
Define the Steps for SQL Server Cursor - SQL Server / TSQL Tutorial
Cursor, Implicit and Explicit Cursor, How to Open, Fetch, Close Cursor
Cursors in sql server
cursor pointer change
cursor mysql
what is cursor in computer
cursor in tamil
cursor types
cursor writing practice
pl/sql
cursor css
cursor kya hota hai
cursor in hindi
SQL Cursors - how and when to use them
Cursors in sql server
Simple cursor in SQL Server with an example
CURSORS IN PL/SQL WITH EXAMPLES
Define the Steps for SQL Server Cursor
Cursors in Sql server | Cursor in database
T-SQL - Cursors
What is a cursor in SQL?
How to use cursor in SQL?
What is the use of a cursor?
How to check cursor in SQL?
sql cursor
sql cursor w3schools
sql cursor example stackoverflow
sql cursor oracle
sql cursor alternative
cursor within cursor in sql server example
sql server cursor example multiple columns
cursor for loop in sql server
cursor in sql server stored procedure
sql cursor example
cursor in sql
mysql cursor
sql if else
sql cursor
Sql cursor example
Sql cursor oracle
sql cursor alternative
cursor in pl/sql
sql cursor example
postgresql cursor
sql cursor vs while

Channel References:
@rejawebs @MSSQLDBAsLife @Microsoft @MSSQLBI_Tutorial @tsqlssis7932 @SQL @sqlquery @sqlquery4042 @sqlinsertdeleteupdate @Amit.Thinks @biwithmina7066 @Programming Only @playwithcode @mycodingproject43
@WiseOwlTutorials @Alex The Analyst
Hash Tag:
#sql #sqlserver #sqlsubquery #mssqlserver #microsoft #sqltips #sqlinsertdeleteupdate #rejawebs official video
cursors_in_sql_server
sql_cursors_-_how_and_when_to_use_them
pl/sql_database_cursors_in_oracle_database
cursor_in_sql_server_2019_with_examples
stored_procedure_in_sql_in_hindi_|_sql_tutorial
sql_server_cursor_example_tamil
cursor_in_sql_-_hindi
what_is_a_cursor?_why_to_avoid_them?
sql_server_cursor_vs_while_exists
cursors_in_sql_server
cursor_pointer_change
cursor_mysql
what_is_cursor_in_computer
cursor_in_tamil
cursor_types
cursor_writing_practice
pl/sql
cursor_css
cursor_kya_hota_hai
cursor_in_hindi
sql_cursors_-_how_and_when_to_use_them
cursors_in_sql_server
simple_cursor_in_sql_server_with_an_example
t-sql_-_cursors
what_is_a_cursor_in_sql?
how_to_use_cursor_in_sql?
what_is_the_use_of_a_cursor?
how_to_check_cursor_in_sql?
sql_cursor
sql_cursor_w3schools
sql_cursor_example_stackoverflow
sql_cursor_oracle
sql_cursor_alternative
sql_cursor_example
cursor_in_sql
mysql_cursor
sql_if_else
sql_cursor
sql_cursor_example
sql_cursor_oracle
sql_cursor_alternative
cursor_in_pl/sql
sql_cursor_example
postgresql_cursor
sql_cursor_vs_while